home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / d / desk_bogo / !Desk_Bogo / c / bogomips next >
Text File  |  1996-04-28  |  1KB  |  48 lines

  1. /*
  2.  *                Standalone BogoMips program
  3.  *
  4.  * Based on code Linux kernel code in init/main.c and
  5.  * include/linux/delay.h
  6.  *
  7.  * For more information on interpreting the results, see the BogoMIPS
  8.  * Mini-HOWTO document.
  9.  *
  10.  * version: 1.3 
  11.  *  author: Jeff Tranter (Jeff_Tranter@Mitel.COM)
  12.  *
  13.  * modified version:
  14.  *  author:  Julyan Bristow
  15.  *  purpose: call as a function from a desktop application for Acorn
  16.  *  RISC OS machines
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include <time.h>
  21.  
  22. /* use the portable version of bogomips */
  23. static void delay(long loops)
  24. {
  25.   long i;
  26.   for (i = loops; i >= 0 ; i--);
  27. }
  28.  
  29.  
  30. int bogo_mips_main(unsigned long *whole,unsigned long *fraction)
  31. {
  32.   unsigned long loops_per_sec = 1;
  33.   unsigned long ticks;
  34.   
  35.   while ((loops_per_sec <<= 1)) {
  36.     ticks = clock();
  37.     delay(loops_per_sec);
  38.     ticks = clock() - ticks;
  39.     if (ticks >= CLOCKS_PER_SEC) {
  40.       loops_per_sec = (loops_per_sec / ticks) * CLOCKS_PER_SEC;
  41.       *whole = loops_per_sec/500000;
  42.       *fraction = (loops_per_sec/5000) % 100;
  43.       return 1;
  44.     }
  45.   }
  46.   return 0;
  47. }
  48.