Skip to content

Commit 8a6dddb

Browse files
andreas-abelcopybara-github
authored andcommitted
Add explicit iteration counts to the Swissmap benchmarks
PiperOrigin-RevId: 736511322 Change-Id: I11c2affcb33f992c9196a5b64f86d95a0d42e9e3
1 parent 7a7978a commit 8a6dddb

File tree

3 files changed

+65
-13
lines changed

3 files changed

+65
-13
lines changed

fleetbench/swissmap/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ cc_library(
1919
"@com_google_absl//absl/container:flat_hash_set",
2020
"@com_google_absl//absl/container:node_hash_set",
2121
"@com_google_absl//absl/random",
22+
"@com_google_absl//absl/strings:string_view",
2223
"@com_google_benchmark//:benchmark",
2324
],
2425
alwayslink = True,

fleetbench/swissmap/cold_swissmap_benchmark.cc

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
#include "absl/container/flat_hash_set.h"
2121
#include "absl/container/node_hash_set.h"
22+
#include "absl/strings/string_view.h"
2223
#include "benchmark/benchmark.h"
24+
#include "fleetbench/common/common.h"
2325
#include "fleetbench/dynamic_registrar.h"
2426
#include "fleetbench/swissmap/swissmap_benchmark.h"
2527

@@ -349,12 +351,36 @@ void RegisterColdBenchmarks() {
349351
ADD_SWISSMAP_BENCHMARKS_TO_LIST(benchmarks,
350352
BM_SWISSMAP_InsertManyUnordered_Cold, 64);
351353
for (auto* benchmark : benchmarks) {
352-
benchmark->ArgNames({"set_size", "density"})
353-
->Ranges({
354-
{1 << 4, 1 << 20},
355-
{static_cast<int64_t>(Density::kMin),
356-
static_cast<int64_t>(Density::kMax)},
357-
});
354+
benchmark->ArgNames({"set_size", "density"});
355+
// If UseExplicitIterationCounts() is false, then the code below is
356+
// equivalent to:
357+
// benchmark->Ranges({
358+
// {1 << 4, 1 << 20},
359+
// {static_cast<int64_t>(Density::kMin),
360+
// static_cast<int64_t>(Density::kMax)},
361+
// });
362+
// We cannot use the same approach if UseExplicitIterationCounts() is true
363+
// because it is not possible to set different iteration counts for
364+
// benchmarks that are part of the same family. We therefore manually do
365+
// what `Ranges()` does, and register a separate benchmark for the special
366+
// case for which we want to set an explicit iteration count.
367+
for (int64_t set_size : {16, 64, 512, 4096, 32768, 262144, 1048576}) {
368+
for (int64_t density = static_cast<int64_t>(Density::kMin);
369+
density <= static_cast<int64_t>(Density::kMax); density++) {
370+
if (UseExplicitIterationCounts() &&
371+
absl::string_view(benchmark->GetName()) ==
372+
"BM_SWISSMAP_InsertHit_Cold<::absl::flat_hash_set, 64>" &&
373+
set_size == 64 && density == static_cast<int64_t>(Density::kMin)) {
374+
REGISTER_BENCHMARK_TEMPLATE(BM_SWISSMAP_InsertHit_Cold,
375+
::absl::flat_hash_set, 64)
376+
->ArgNames({"set_size", "density"})
377+
->Args({set_size, density})
378+
->Iterations(5000000);
379+
} else {
380+
benchmark->Args({set_size, density});
381+
}
382+
}
383+
}
358384
}
359385

360386
std::vector<benchmark::internal::Benchmark*> erase_insert_benchmarks;

fleetbench/swissmap/hot_swissmap_benchmark.cc

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
#include "absl/container/flat_hash_set.h"
2626
#include "absl/container/node_hash_set.h"
2727
#include "absl/random/random.h"
28+
#include "absl/strings/string_view.h"
2829
#include "benchmark/benchmark.h"
30+
#include "fleetbench/common/common.h"
2931
#include "fleetbench/dynamic_registrar.h"
3032
#include "fleetbench/swissmap/swissmap_benchmark.h"
3133

@@ -538,13 +540,36 @@ void RegisterHotBenchmarks() {
538540
ADD_SWISSMAP_BENCHMARKS_TO_LIST(benchmarks,
539541
BM_SWISSMAP_InsertManyUnordered_Hot, 64);
540542
for (auto* benchmark : benchmarks) {
541-
benchmark->ArgNames({"set_size", "density"})
542-
->RangeMultiplier(2)
543-
->Ranges({
544-
{1, 1 << 20},
545-
{static_cast<int64_t>(Density::kMin),
546-
static_cast<int64_t>(Density::kMax)},
547-
});
543+
benchmark->ArgNames({"set_size", "density"});
544+
// If UseExplicitIterationCounts() is false, then the code below is
545+
// equivalent to:
546+
// benchmark->RangeMultiplier(2)->Ranges({
547+
// {1, 1 << 20},
548+
// {static_cast<int64_t>(Density::kMin),
549+
// static_cast<int64_t>(Density::kMax)},
550+
// });
551+
// We cannot use the same approach if UseExplicitIterationCounts() is true
552+
// because it is not possible to set different iteration counts for
553+
// benchmarks that are part of the same family. We therefore manually do
554+
// what `Ranges()` does, and register a separate benchmark for the special
555+
// case for which we want to set an explicit iteration count.
556+
for (int64_t set_size = 1; set_size <= (1 << 20); set_size *= 2) {
557+
for (int64_t density = static_cast<int64_t>(Density::kMin);
558+
density <= static_cast<int64_t>(Density::kMax); density++) {
559+
if (UseExplicitIterationCounts() &&
560+
absl::string_view(benchmark->GetName()) ==
561+
"BM_SWISSMAP_InsertHit_Hot<::absl::flat_hash_set, 64>" &&
562+
set_size == 64 && density == static_cast<int64_t>(Density::kMin)) {
563+
REGISTER_BENCHMARK_TEMPLATE(BM_SWISSMAP_InsertHit_Hot,
564+
::absl::flat_hash_set, 64)
565+
->ArgNames({"set_size", "density"})
566+
->Args({set_size, density})
567+
->Iterations(100000000);
568+
} else {
569+
benchmark->Args({set_size, density});
570+
}
571+
}
572+
}
548573
}
549574

550575
std::vector<benchmark::internal::Benchmark*> erase_insert_benchmarks;

0 commit comments

Comments
 (0)