mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 11:37:35 +00:00
31 lines
1.4 KiB
C
31 lines
1.4 KiB
C
#ifndef COSMOPOLITAN_LIBC_BENCH_H_
|
|
#define COSMOPOLITAN_LIBC_BENCH_H_
|
|
#include "libc/bits/safemacros.internal.h"
|
|
#include "libc/nexgen32e/bench.h"
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
COSMOPOLITAN_C_START_
|
|
|
|
/**
|
|
* @fileoverview Microbenchmarking Toolz.
|
|
*/
|
|
|
|
#ifndef BENCHLOOP
|
|
#define BENCHLOOP(START, STOP, N, INIT, EXPR) \
|
|
({ \
|
|
unsigned long Iter, Count; \
|
|
uint64_t Time1, Time2; \
|
|
double Average; \
|
|
for (Average = 1, Iter = 1, Count = (N); Iter < Count; ++Iter) { \
|
|
INIT; \
|
|
Time1 = START(); \
|
|
EXPR; \
|
|
Time2 = STOP(); \
|
|
Average += 1. / Iter * (unsignedsubtract(Time2, Time1) - Average); \
|
|
} \
|
|
Average; \
|
|
})
|
|
#endif /* BENCHLOOP */
|
|
|
|
COSMOPOLITAN_C_END_
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
#endif /* COSMOPOLITAN_LIBC_BENCH_H_ */
|