Skip to content

Commit eeed589

Browse files
authored
[libc] Correctly Run Multiple Benchmarks in the Same File (#98467)
There was previously an issue where registering multiple benchmarks in the same file would only give the results for the last benchmark to run. This PR fixes the issue. @jhuber6
1 parent 117cc4a commit eeed589

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

libc/benchmarks/gpu/LibcGpuBenchmark.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,10 @@ void Benchmark::run_benchmarks() {
5252
uint64_t id = gpu::get_thread_id();
5353
gpu::sync_threads();
5454

55-
for (Benchmark *b : benchmarks)
55+
for (Benchmark *b : benchmarks) {
5656
results[id] = b->run();
57-
gpu::sync_threads();
58-
if (id == 0) {
59-
for (Benchmark const *b : benchmarks) {
57+
gpu::sync_threads();
58+
if (id == 0) {
6059
BenchmarkResult all_results = reduce_results(results);
6160
constexpr auto GREEN = "\033[32m";
6261
constexpr auto RESET = "\033[0m";

libc/benchmarks/gpu/src/ctype/isalnum_benchmark.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,16 @@ uint64_t BM_IsAlnum() {
66
char x = 'c';
77
return LIBC_NAMESPACE::latency(LIBC_NAMESPACE::isalnum, x);
88
}
9-
BENCHMARK(LlvmLibcIsAlNumGpuBenchmark, IsAlnumWrapper, BM_IsAlnum);
9+
BENCHMARK(LlvmLibcIsAlNumGpuBenchmark, IsAlnum, BM_IsAlnum);
10+
11+
uint64_t BM_IsAlnumCapital() {
12+
char x = 'A';
13+
return LIBC_NAMESPACE::latency(LIBC_NAMESPACE::isalnum, x);
14+
}
15+
BENCHMARK(LlvmLibcIsAlNumGpuBenchmark, IsAlnumCapital, BM_IsAlnumCapital);
16+
17+
uint64_t BM_IsAlnumNotAlnum() {
18+
char x = '{';
19+
return LIBC_NAMESPACE::latency(LIBC_NAMESPACE::isalnum, x);
20+
}
21+
BENCHMARK(LlvmLibcIsAlNumGpuBenchmark, IsAlnumNotAlnum, BM_IsAlnumNotAlnum);

0 commit comments

Comments
 (0)