Skip to content

Commit 6274e0b

Browse files
andreas-abelcopybara-github
authored andcommitted
Add explicit iteration counts to the mem benchmarks.
PiperOrigin-RevId: 735772439 Change-Id: I72479ab3a8905d990b4f2a0ac19f00d6ba934389
1 parent cd20746 commit 6274e0b

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

fleetbench/libc/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ cc_library(
2020
"//fleetbench:dynamic_registrar",
2121
"//fleetbench/common",
2222
"@com_google_absl//absl/algorithm:container",
23+
"@com_google_absl//absl/base:no_destructor",
2324
"@com_google_absl//absl/container:btree",
25+
"@com_google_absl//absl/container:flat_hash_map",
2426
"@com_google_absl//absl/log:check",
2527
"@com_google_absl//absl/random:distributions",
2628
"@com_google_absl//absl/strings",

fleetbench/libc/mem_benchmark.cc

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
#include <vector>
2929

3030
#include "absl/algorithm/container.h"
31+
#include "absl/base/no_destructor.h"
3132
#include "absl/container/btree_map.h"
33+
#include "absl/container/flat_hash_map.h"
3234
#include "absl/log/check.h"
3335
#include "absl/random/distributions.h"
3436
#include "absl/strings/str_cat.h"
@@ -52,6 +54,19 @@ static constexpr float kComparisonEqualProbability = 0.4;
5254
// 64 bytes is a common size for cache lines.
5355
static constexpr size_t kCacheLineSize = 64;
5456

57+
// Maps the default benchmarks to their minimum iteration counts.
58+
absl::NoDestructor<absl::flat_hash_map<std::string, benchmark::IterationCount>>
59+
kDefaultBenchmarks({{"BM_LIBC_Bcmp_Fleet_L1", 800'000'000},
60+
{"BM_LIBC_Memcmp_Fleet_L1", 1'000'000'000},
61+
{"BM_LIBC_Memcpy_Fleet_L1", 5'000'000'000},
62+
{"BM_LIBC_Memmove_Fleet_L1", 2'000'000'000},
63+
{"BM_LIBC_Memset_Fleet_L1", 10'000'000'000},
64+
{"BM_LIBC_Bcmp_Fleet_Cold", 200'000'000},
65+
{"BM_LIBC_Memcmp_Fleet_Cold", 500'000'000},
66+
{"BM_LIBC_Memcpy_Fleet_Cold", 1'000'000'000},
67+
{"BM_LIBC_Memmove_Fleet_Cold", 500'000'000},
68+
{"BM_LIBC_Memset_Fleet_Cold", 3'000'000'000}});
69+
5570
// Returns the sum of the size_bytes elements.
5671
size_t ComputeTotalNumBytes(const BM_Mem_Parameters &parameters) {
5772
return std::accumulate(parameters.size_bytes.begin(),
@@ -522,10 +537,16 @@ void RegisterBenchmarks() {
522537
for (const auto &[cache_name, cache_size] : cache_resident_info) {
523538
std::string benchmark_name =
524539
absl::StrCat("BM_LIBC_", distribution_name, "_", cache_name);
525-
benchmark::RegisterBenchmark(
526-
benchmark_name, memory_benchmark, memory_size_distribution,
527-
overlap_probability, alignment_distribution, buffer_counter,
528-
memory_function, cache_size, suffix_name);
540+
benchmark::internal::Benchmark *benchmark =
541+
benchmark::RegisterBenchmark(
542+
benchmark_name, memory_benchmark, memory_size_distribution,
543+
overlap_probability, alignment_distribution, buffer_counter,
544+
memory_function, cache_size, suffix_name);
545+
// Use the default minimum iteration count if possible.
546+
auto it = kDefaultBenchmarks->find(benchmark_name);
547+
if (it != kDefaultBenchmarks->end() && UseExplicitIterationCounts()) {
548+
benchmark->Iterations(it->second);
549+
}
529550
}
530551
}
531552
}
@@ -535,16 +556,9 @@ class BenchmarkRegisterer {
535556
public:
536557
BenchmarkRegisterer() {
537558
DynamicRegistrar::Get()->AddCallback(RegisterBenchmarks);
538-
DynamicRegistrar::Get()->AddDefaultFilter("BM_LIBC_Bcmp_Fleet_L1");
539-
DynamicRegistrar::Get()->AddDefaultFilter("BM_LIBC_Memcmp_Fleet_L1");
540-
DynamicRegistrar::Get()->AddDefaultFilter("BM_LIBC_Memcpy_Fleet_L1");
541-
DynamicRegistrar::Get()->AddDefaultFilter("BM_LIBC_Memmove_Fleet_L1");
542-
DynamicRegistrar::Get()->AddDefaultFilter("BM_LIBC_Memset_Fleet_L1");
543-
DynamicRegistrar::Get()->AddDefaultFilter("BM_LIBC_Bcmp_Fleet_Cold");
544-
DynamicRegistrar::Get()->AddDefaultFilter("BM_LIBC_Memcmp_Fleet_Cold");
545-
DynamicRegistrar::Get()->AddDefaultFilter("BM_LIBC_Memcpy_Fleet_Cold");
546-
DynamicRegistrar::Get()->AddDefaultFilter("BM_LIBC_Memmove_Fleet_Cold");
547-
DynamicRegistrar::Get()->AddDefaultFilter("BM_LIBC_Memset_Fleet_Cold");
559+
for (const auto &[benchmark_name, _] : *kDefaultBenchmarks) {
560+
DynamicRegistrar::Get()->AddDefaultFilter(benchmark_name);
561+
}
548562
}
549563
};
550564

0 commit comments

Comments
 (0)