1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#define DO_BENCH_CUSTOM(printf_func, min_time, min_iters, func, ...) \
{ \
    long t1, t2, t_end; \
    long count = 0; \
    uint64_t count_long; \
    t2 = *(rb->current_tick); \
    while (t2 != (t1 = *(rb->current_tick))); \
    t_end = t1 + min_time; \
    do { \
        func(__VA_ARGS__); \
        count++; \
        t2 = *(rb->current_tick); \
    } while (TIME_BEFORE(t2, t_end) || count < min_iters); \
    t2 -= t1; \
    count_long = (uint64_t)count * HZ; \
    count_long += t2 >> 1; \
    count_long /= t2; \
    printf_func(#func ": %01d/sec", (int)count_long); \
    rb->yield(); \
}

#define DO_BENCH(...) DO_BENCH_CUSTOM(1000, 10, __VA_ARGS__)
#define LOG_PRINTF(format, ...) rb->fdprintf(log_fd, format "\n" , ## __VA_ARGS__)