[libc-commits] [libc] [libc] Correctly Run Multiple Benchmarks in the Same File (PR #98467)
via libc-commits
libc-commits at lists.llvm.org
Thu Jul 11 04:46:40 PDT 2024
https://github.com/jameshu15869 created https://github.com/llvm/llvm-project/pull/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
>From 65ebfc0ab7ccaa4949c5ade1b2f985c527d26f05 Mon Sep 17 00:00:00 2001
From: jameshu15869 <jhudson15869 at gmail.com>
Date: Thu, 11 Jul 2024 07:41:25 -0400
Subject: [PATCH] correctly run multiple benchmarks in the same file
---
libc/benchmarks/gpu/LibcGpuBenchmark.cpp | 7 +++----
.../benchmarks/gpu/src/ctype/isalnum_benchmark.cpp | 14 +++++++++++++-
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/libc/benchmarks/gpu/LibcGpuBenchmark.cpp b/libc/benchmarks/gpu/LibcGpuBenchmark.cpp
index 7f60c9cc4a2f4..3dd83cef6d4df 100644
--- a/libc/benchmarks/gpu/LibcGpuBenchmark.cpp
+++ b/libc/benchmarks/gpu/LibcGpuBenchmark.cpp
@@ -52,11 +52,10 @@ void Benchmark::run_benchmarks() {
uint64_t id = gpu::get_thread_id();
gpu::sync_threads();
- for (Benchmark *b : benchmarks)
+ for (Benchmark *b : benchmarks) {
results[id] = b->run();
- gpu::sync_threads();
- if (id == 0) {
- for (Benchmark const *b : benchmarks) {
+ gpu::sync_threads();
+ if (id == 0) {
BenchmarkResult all_results = reduce_results(results);
constexpr auto GREEN = "\033[32m";
constexpr auto RESET = "\033[0m";
diff --git a/libc/benchmarks/gpu/src/ctype/isalnum_benchmark.cpp b/libc/benchmarks/gpu/src/ctype/isalnum_benchmark.cpp
index 4050bc0ec77b9..6f8d247902f76 100644
--- a/libc/benchmarks/gpu/src/ctype/isalnum_benchmark.cpp
+++ b/libc/benchmarks/gpu/src/ctype/isalnum_benchmark.cpp
@@ -6,4 +6,16 @@ uint64_t BM_IsAlnum() {
char x = 'c';
return LIBC_NAMESPACE::latency(LIBC_NAMESPACE::isalnum, x);
}
-BENCHMARK(LlvmLibcIsAlNumGpuBenchmark, IsAlnumWrapper, BM_IsAlnum);
+BENCHMARK(LlvmLibcIsAlNumGpuBenchmark, IsAlnum, BM_IsAlnum);
+
+uint64_t BM_IsAlnumCapital() {
+ char x = 'A';
+ return LIBC_NAMESPACE::latency(LIBC_NAMESPACE::isalnum, x);
+}
+BENCHMARK(LlvmLibcIsAlNumGpuBenchmark, IsAlnumCapital, BM_IsAlnumCapital);
+
+uint64_t BM_IsAlnumNotAlnum() {
+ char x = '{';
+ return LIBC_NAMESPACE::latency(LIBC_NAMESPACE::isalnum, x);
+}
+BENCHMARK(LlvmLibcIsAlNumGpuBenchmark, IsAlnumNotAlnum, BM_IsAlnumNotAlnum);
More information about the libc-commits
mailing list