Created
November 7, 2012 07:59
-
-
Save kanru/4030106 to your computer and use it in GitHub Desktop.
Little benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Any copyright is dedicated to the Public Domain. | |
* http://creativecommons.org/publicdomain/zero/1.0/ | |
* | |
* Compile using |gcc -O0 bench.c -o bench| | |
*/ | |
#include <stdio.h> | |
#include <sys/time.h> | |
#define TIMES 10000000 | |
int main(int argc, char *argv[]) | |
{ | |
struct timeval start; | |
struct timeval end; | |
while (1) { | |
gettimeofday(&start, NULL); | |
// tight loop | |
unsigned long i; | |
for (i = 0; i < TIMES; ++i); | |
gettimeofday(&end, NULL); | |
printf("speed %g loop/us\n", | |
(double)TIMES / ((end.tv_sec-start.tv_sec)*1000000 + | |
end.tv_usec - start.tv_usec)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment