mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 11:37:35 +00:00
fa20edc44d
- Remove most __ASSEMBLER__ __LINKER__ ifdefs - Rename libc/intrin/bits.h to libc/serialize.h - Block pthread cancelation in fchmodat() polyfill - Remove `clang-format off` statements in third_party
47 lines
2 KiB
C
47 lines
2 KiB
C
#ifndef COSMOPOLITAN_LIBC_BENCH_H_
|
|
#define COSMOPOLITAN_LIBC_BENCH_H_
|
|
#include "libc/nexgen32e/bench.h"
|
|
COSMOPOLITAN_C_START_
|
|
|
|
/**
|
|
* @fileoverview Microbenchmarking Toolz.
|
|
*/
|
|
|
|
#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; \
|
|
})
|
|
|
|
#ifndef BENCHLOOP
|
|
/* 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; \
|
|
})
|
|
#endif /* BENCHLOOP */
|
|
|
|
COSMOPOLITAN_C_END_
|
|
#endif /* COSMOPOLITAN_LIBC_BENCH_H_ */
|