initial implementation of xorshift128 and xorshift128plus
This commit is contained in:
commit
45342ac49d
6 changed files with 120 additions and 0 deletions
46
benchmark.c
Normal file
46
benchmark.c
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue