#include #include #include "xorshift.h" struct timespec clock_diff(struct timespec start, struct timespec stop) { struct timespec diff; if ((stop.tv_nsec-start.tv_nsec) < 0) { diff.tv_sec = stop.tv_sec - start.tv_sec - 1; diff.tv_nsec = 1e9 + stop.tv_nsec - start.tv_nsec; } else { diff.tv_sec = stop.tv_sec - start.tv_sec; diff.tv_nsec = stop.tv_nsec - start.tv_nsec; } return diff; } #define BENCHMARK(func) \ { \ struct timespec start, stop, diff; \ \ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); \ \ for (size_t i = 0; i < 1e9; ++i) \ (void)func(); \ \ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &stop); \ diff = clock_diff(start, stop); \ \ printf("%ld:%ld\n", (long)diff.tv_sec, (long)diff.tv_nsec); \ } \ int main() { BENCHMARK(xorshift128); BENCHMARK(xorshift128plus); return 0; }