1 #define _POSIX_C_SOURCE 200809L
10 #define B(t) void t();
16 void error__(const char *n, int l, const char *s, ...) {
17 fprintf(stderr, "use error in tests only\n");
21 static unsigned long long start;
22 static unsigned long long ns;
23 //static unsigned long long bytes;
25 #define SEC 1000000000ULL
26 #define MAXN 1000000000
28 static unsigned long long nsclock() {
32 r = clock_gettime(CLOCK_MONOTONIC, &ts);
34 fprintf(stderr, "bench: clock_gettime failed: %s\n", strerror(errno));
37 return ts.tv_sec*SEC + ts.tv_nsec;
47 ns += nsclock() - start;
58 unsigned long long n = ns/N;
74 static void run(const char *name, void (*f)()) {
75 fprintf(stderr, "%s:", name);
76 for (N=1; ; N=nextN()) {
81 // fprintf(stderr, "%10d%12llu\n", N, ns);
82 if (ns > SEC || N >= MAXN)
85 fprintf(stderr, "bench: fatal: N <= 0\n");
90 fprintf(stderr, "%10d%10llu ns/op\n", N, ns/N);
92 fprintf(stderr, "%10d%13.2f ns/op\n", N, (double)ns/N);
96 #define B(t) run(#t, t);