-
-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid legacy instruction penalties on x86
- Loading branch information
Showing
16 changed files
with
199 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.