Last active
February 24, 2017 13:44
-
-
Save romuald/6853335 to your computer and use it in GitHub Desktop.
Doing some benchmarks on a lib, found out that gettimeofday is way faster on MacOS (10.6) than Linux (3.8.0)(50ms vs 600+ms on the same machine, 64bit in both cases)
This file contains hidden or 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
#include <stdio.h> | |
#include <time.h> | |
#include <sys/time.h> | |
#define COUNT 800000 | |
int main() { | |
long i = 0; | |
long start, end; | |
struct timeval tstart, tend, tt; | |
gettimeofday(&tstart, NULL); | |
for (; i < 800000; i++) { | |
gettimeofday(&tt, NULL); | |
} | |
gettimeofday(&tend, NULL); | |
start = (long)tstart.tv_sec * 1000 + (long)tstart.tv_usec / 1000; | |
end = (long)tend.tv_sec * 1000 + (long)tend.tv_usec / 1000; | |
printf("Done in %ldms (%ld op/s)\n", end - start, COUNT / (end-start) * 1000); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment