2020-06-15 14:18:57 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_BENCH_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_BENCH_H_
|
|
|
|
#include "libc/nexgen32e/bench.h"
|
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
|
|
|
|
/**
|
2021-08-07 14:05:19 +00:00
|
|
|
* @fileoverview Microbenchmarking Toolz.
|
2020-06-15 14:18:57 +00:00
|
|
|
*/
|
|
|
|
|
2023-06-03 15:12:13 +00:00
|
|
|
#define BENCHLOOPER(START, STOP, N, EXPR) \
|
|
|
|
({ \
|
|
|
|
long Iter = 1; \
|
|
|
|
long Toto = (N); \
|
|
|
|
uint64_t Time1 = START(); \
|
|
|
|
asm volatile("" ::: "memory"); \
|
|
|
|
for (; Iter < Toto; ++Iter) { \
|
|
|
|
asm volatile("" ::: "memory"); \
|
|
|
|
EXPR; \
|
|
|
|
asm volatile("" ::: "memory"); \
|
|
|
|
} \
|
|
|
|
asm volatile("" ::: "memory"); \
|
|
|
|
uint64_t Time2 = STOP(); \
|
|
|
|
(double)(long)(Time2 - Time1) / Iter; \
|
|
|
|
})
|
|
|
|
|
2021-02-02 16:14:45 +00:00
|
|
|
#ifndef BENCHLOOP
|
2023-06-03 15:12:13 +00:00
|
|
|
/* TODO(jart): DELETE */
|
|
|
|
#define BENCHLOOP(START, STOP, N, INIT, EXPR) \
|
|
|
|
({ \
|
|
|
|
double Average; \
|
|
|
|
uint64_t Time1, Time2; \
|
|
|
|
unsigned long Iter, Count; \
|
|
|
|
for (Average = 1, Iter = 1, Count = (N); Iter < Count; ++Iter) { \
|
|
|
|
INIT; \
|
|
|
|
Time1 = START(); \
|
|
|
|
asm volatile("" ::: "memory"); \
|
|
|
|
EXPR; \
|
|
|
|
asm volatile("" ::: "memory"); \
|
|
|
|
Time2 = STOP(); \
|
|
|
|
Average += 1. / Iter * ((int)(Time2 - Time1) - Average); \
|
|
|
|
} \
|
|
|
|
Average; \
|
2020-06-15 14:18:57 +00:00
|
|
|
})
|
2021-02-02 16:14:45 +00:00
|
|
|
#endif /* BENCHLOOP */
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
|
|
COSMOPOLITAN_C_END_
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_BENCH_H_ */
|