Skip to content

Instantly share code, notes, and snippets.

@kanru
Created November 7, 2012 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanru/4030106 to your computer and use it in GitHub Desktop.
Save kanru/4030106 to your computer and use it in GitHub Desktop.
Little benchmark
/* 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