mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-13 06:29:11 +00:00
Avoid legacy instruction penalties on x86
This commit is contained in:
parent
1fba310e22
commit
8d8aecb6d9
16 changed files with 199 additions and 158 deletions
|
@ -22,6 +22,7 @@ LIBC_TESTLIB_A_ASSETS = \
|
|||
LIBC_TESTLIB_A_HDRS = \
|
||||
libc/testlib/aspect.internal.h \
|
||||
libc/testlib/bench.h \
|
||||
libc/testlib/benchmark.h \
|
||||
libc/testlib/blocktronics.h \
|
||||
libc/testlib/ezbench.h \
|
||||
libc/testlib/fastrandomstring.h \
|
||||
|
|
26
libc/testlib/benchmark.h
Normal file
26
libc/testlib/benchmark.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_TESTLIB_BENCHMARK_H_
|
||||
#define COSMOPOLITAN_LIBC_TESTLIB_BENCHMARK_H_
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define BENCHMARK(ITERATIONS, WORK_PER_RUN, CODE) \
|
||||
do { \
|
||||
struct timespec start = timespec_real(); \
|
||||
for (int __i = 0; __i < ITERATIONS; ++__i) { \
|
||||
asm volatile("" ::: "memory"); \
|
||||
CODE; \
|
||||
} \
|
||||
long long work = ((WORK_PER_RUN) ? (WORK_PER_RUN) : 1) * (ITERATIONS); \
|
||||
double nanos = \
|
||||
(timespec_tonanos(timespec_sub(timespec_real(), start)) + work - 1) / \
|
||||
(double)work; \
|
||||
if (nanos < 1000) { \
|
||||
printf("%10g ns %2dx %s\n", nanos, (ITERATIONS), #CODE); \
|
||||
} else { \
|
||||
printf("%10lld ns %2dx %s\n", (long long)nanos, (ITERATIONS), #CODE); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* COSMOPOLITAN_LIBC_TESTLIB_BENCHMARK_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue