Skip to content

Commit 8bfe762

Browse files
andreas-abelcopybara-github
authored andcommitted
Add explicit iteration counts to the cord, hashing, and proto benchmarks
PiperOrigin-RevId: 736568830 Change-Id: If01e162f1c0e72a6550c45fc7590515db0a49a3b
1 parent 323a4f7 commit 8bfe762

File tree

5 files changed

+45
-18
lines changed

5 files changed

+45
-18
lines changed

fleetbench/hashing/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ cc_library(
99
deps = [
1010
"//fleetbench:dynamic_registrar",
1111
"//fleetbench/common",
12+
"@com_google_absl//absl/base:no_destructor",
1213
"@com_google_absl//absl/container:btree",
14+
"@com_google_absl//absl/container:flat_hash_map",
1315
"@com_google_absl//absl/crc:crc32c",
1416
"@com_google_absl//absl/hash",
1517
"@com_google_absl//absl/strings",

fleetbench/hashing/hashing_benchmark.cc

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
#include <utility>
2626
#include <vector>
2727

28+
#include "absl/base/no_destructor.h"
2829
#include "absl/container/btree_map.h"
30+
#include "absl/container/flat_hash_map.h"
2931
#include "absl/crc/crc32c.h"
3032
#include "absl/hash/hash.h"
3133
#include "absl/strings/str_cat.h"
@@ -39,6 +41,14 @@ namespace hashing {
3941

4042
using CacheInfo = benchmark::CPUInfo::CacheInfo;
4143

44+
// Maps the default benchmarks to their minimum iteration counts.
45+
// We use the fleet-wide cold distributions as the defaults.
46+
absl::NoDestructor<absl::flat_hash_map<std::string, benchmark::IterationCount>>
47+
kDefaultBenchmarks(
48+
{{"BM_HASHING_Extendcrc32cinternal_Fleet_cold", 2'000'000'000},
49+
{"BM_HASHING_Computecrc32c_Fleet_cold", 1'000'000'000},
50+
{"BM_HASHING_Combine_contiguous_Fleet_cold", 500'000'000}});
51+
4252
struct BM_Hashing_Parameters {
4353
std::vector<int> str_lengths;
4454
absl::string_view sv;
@@ -240,9 +250,17 @@ void RegisterBenchmarks() {
240250
for (const auto &[hot_str, hot] : cache_resident_info) {
241251
std::string benchmark_name =
242252
absl::StrCat("BM_HASHING_", application, "_", hot_str);
243-
benchmark::RegisterBenchmark(benchmark_name, BM_Hashing,
244-
hashing_size_distribution, hash_function,
245-
hot, suffix_name);
253+
benchmark::internal::Benchmark *benchmark =
254+
benchmark::RegisterBenchmark(benchmark_name, BM_Hashing,
255+
hashing_size_distribution,
256+
hash_function, hot, suffix_name);
257+
// Use the default minimum iteration count if possible.
258+
if (UseExplicitIterationCounts()) {
259+
auto it = kDefaultBenchmarks->find(benchmark_name);
260+
if (it != kDefaultBenchmarks->end()) {
261+
benchmark->Iterations(it->second);
262+
}
263+
}
246264
}
247265
}
248266
}
@@ -252,14 +270,9 @@ class BenchmarkRegisterer {
252270
public:
253271
BenchmarkRegisterer() {
254272
DynamicRegistrar::Get()->AddCallback(RegisterBenchmarks);
255-
256-
// We use the fleet-wide cold distributions as the defaults.
257-
DynamicRegistrar::Get()->AddDefaultFilter(
258-
"BM_HASHING_Extendcrc32cinternal_Fleet_cold");
259-
DynamicRegistrar::Get()->AddDefaultFilter(
260-
"BM_HASHING_Computecrc32c_Fleet_cold");
261-
DynamicRegistrar::Get()->AddDefaultFilter(
262-
"BM_HASHING_Combine_contiguous_Fleet_cold");
273+
for (const auto &[benchmark_name, _] : *kDefaultBenchmarks) {
274+
DynamicRegistrar::Get()->AddDefaultFilter(benchmark_name);
275+
}
263276
}
264277
};
265278

fleetbench/libc/mem_benchmark.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,11 @@ void RegisterBenchmarks() {
543543
overlap_probability, alignment_distribution, buffer_counter,
544544
memory_function, cache_size, suffix_name);
545545
// 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);
546+
if (UseExplicitIterationCounts()) {
547+
auto it = kDefaultBenchmarks->find(benchmark_name);
548+
if (it != kDefaultBenchmarks->end()) {
549+
benchmark->Iterations(it->second);
550+
}
549551
}
550552
}
551553
}

fleetbench/proto/benchmark.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <cstdint>
1717

18+
#include "fleetbench/common/common.h"
1819
#include "fleetbench/dynamic_registrar.h"
1920
#include "fleetbench/productivity_reporter.h"
2021
#include "fleetbench/proto/lifecycle.h"
@@ -53,7 +54,11 @@ void BM_Protogen_NoArena(benchmark::State& state) {
5354
}
5455

5556
void RegisterBenchmarks() {
56-
benchmark::RegisterBenchmark("BM_PROTO_Arena", BM_Protogen_Arena);
57+
benchmark::internal::Benchmark* benchmark =
58+
benchmark::RegisterBenchmark("BM_PROTO_Arena", BM_Protogen_Arena);
59+
if (UseExplicitIterationCounts()) {
60+
benchmark->Iterations(100);
61+
}
5762
benchmark::RegisterBenchmark("BM_PROTO_NoArena", BM_Protogen_NoArena);
5863
}
5964

fleetbench/stl/cord_benchmark.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "absl/strings/cord.h"
1919
#include "benchmark/benchmark.h"
20+
#include "fleetbench/common/common.h"
2021
#include "fleetbench/dynamic_registrar.h"
2122
#include "fleetbench/stl/generated_cord_benchmarks.h"
2223

@@ -35,9 +36,13 @@ static void BM_Cord(benchmark::State &state,
3536

3637
void RegisterBenchmarks() {
3738
for (const auto &benchmark : GetBenchmarks()) {
38-
benchmark::RegisterBenchmark(benchmark.name, BM_Cord,
39-
benchmark.benchmark_code,
40-
benchmark.benchmark_setup, benchmark.label);
39+
benchmark::internal::Benchmark *registered_benchmark =
40+
benchmark::RegisterBenchmark(
41+
benchmark.name, BM_Cord, benchmark.benchmark_code,
42+
benchmark.benchmark_setup, benchmark.label);
43+
if (UseExplicitIterationCounts() && benchmark.name == "BM_CORD_Fleet") {
44+
registered_benchmark->Iterations(100000);
45+
}
4146
}
4247
}
4348

0 commit comments

Comments
 (0)