"Fossies" - the Fresh Open Source Software Archive

Member "linux_logo-6.0/libsysinfo-0.3.0/all/bogomips.c" (8 May 2020, 869 Bytes) of package /linux/misc/linux_logo-6.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #ifndef linux
    2 /*
    3  *                Standalone BogoMips program
    4  *
    5  * Based on code Linux kernel code in init/main.c and
    6  * include/linux/delay.h
    7  *
    8  * For more information on interpreting the results, see the BogoMIPS
    9  * Mini-HOWTO document.
   10  *
   11  * version: 1.3
   12  *  author: Jeff Tranter (Jeff_Tranter@Mitel.COM)
   13  *
   14  * Modified for inclusion with Linux_Logo -- Vince Weaver
   15  */
   16 
   17 #include <stdio.h>
   18 #include <time.h>
   19 
   20 /* portable version */
   21 static void delay(int loops) {
   22     long i;
   23     for (i = loops; i >= 0 ; i--)
   24         ;
   25 }
   26 
   27 float external_bogomips(void) {
   28 
   29     unsigned long loops_per_sec = 1;
   30     unsigned long ticks;
   31 
   32     while ((loops_per_sec <<= 1)) {
   33         ticks = clock();
   34         delay(loops_per_sec);
   35         ticks = clock() - ticks;
   36         if (ticks >= CLOCKS_PER_SEC) {
   37             loops_per_sec = (loops_per_sec / ticks)*CLOCKS_PER_SEC;
   38             return (float)loops_per_sec/500000;
   39         }
   40     }
   41     return -1;
   42 }
   43 
   44 #endif