#ifdef hpux #define _INCLUDE_POSIX_SOURCE #endif #include #include #include #ifdef hpux #include #endif /* MIPs is guestimated by incrementing a counter in a for loop for one second, and multiplied by 10 (guess of # instructions). Because of the alarm firing as a signal, the loop condition must be in non-cached memory. So this will affect some architectures differently. Also don't compile optimized, as the loop may go away entirely! */ volatile int elapsed = 0; void bang(int sig) { elapsed = 1; } void main() { int ips = 0; #ifdef hpux /* It was hoped that there may be some HP info available in here. Sadly...*/ struct sysinfo sib, *si = 0; si = get_sysinfo (&sib); if (!si) si = &sib; printf("cpu=%d, proc_cnt=%d, max_proc_cnt=%d, syscall=%d\n", si->cpu, si->proc_cnt, si->max_proc_cnt, si->syscall); #endif sleep(1); /* to synchronize the clock ! */ signal(SIGALRM, bang); alarm(1); for (ips = 0; elapsed == 0; ips++) ; printf("Processor speed = %2.2f MIPs! :-) \n", ( (double)ips * 10 /*fudge*/)/1000000.0); }