[perf] Add set ieration and lookup benchmarks.
This commit is contained in:
parent
40975fc3c2
commit
057ec2c953
|
@ -18,6 +18,7 @@ void RandomSet(unsigned size, unsigned max_value, hb_set_t* out) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Insert a single value into set of varying sizes. */
|
||||||
static void BM_SetInsert(benchmark::State& state) {
|
static void BM_SetInsert(benchmark::State& state) {
|
||||||
unsigned set_size = state.range(0);
|
unsigned set_size = state.range(0);
|
||||||
unsigned max_value = state.range(0) * state.range(1);
|
unsigned max_value = state.range(0) * state.range(1);
|
||||||
|
@ -46,4 +47,51 @@ BENCHMARK(BM_SetInsert)
|
||||||
benchmark::CreateDenseRange(2, 8, /*step=*/2) // Density
|
benchmark::CreateDenseRange(2, 8, /*step=*/2) // Density
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/* Single value lookup on sets of various sizes. */
|
||||||
|
static void BM_SetLookup(benchmark::State& state) {
|
||||||
|
unsigned set_size = state.range(0);
|
||||||
|
unsigned max_value = state.range(0) * state.range(1);
|
||||||
|
|
||||||
|
hb_set_t* original = hb_set_create ();
|
||||||
|
RandomSet(set_size, max_value, original);
|
||||||
|
assert(hb_set_get_population(original) == set_size);
|
||||||
|
|
||||||
|
for (auto _ : state) {
|
||||||
|
benchmark::DoNotOptimize(
|
||||||
|
hb_set_has (original, rand() % max_value));
|
||||||
|
}
|
||||||
|
|
||||||
|
hb_set_destroy(original);
|
||||||
|
}
|
||||||
|
BENCHMARK(BM_SetLookup)
|
||||||
|
->ArgsProduct({
|
||||||
|
benchmark::CreateRange(1 << 10, 1 << 16, 8), // Set size
|
||||||
|
benchmark::CreateDenseRange(2, 8, /*step=*/2) // Density
|
||||||
|
});
|
||||||
|
|
||||||
|
/* Full iteration of sets of varying sizes. */
|
||||||
|
static void BM_SetIteration(benchmark::State& state) {
|
||||||
|
unsigned set_size = state.range(0);
|
||||||
|
unsigned max_value = state.range(0) * state.range(1);
|
||||||
|
|
||||||
|
hb_set_t* original = hb_set_create ();
|
||||||
|
RandomSet(set_size, max_value, original);
|
||||||
|
assert(hb_set_get_population(original) == set_size);
|
||||||
|
|
||||||
|
for (auto _ : state) {
|
||||||
|
hb_codepoint_t cp = HB_SET_VALUE_INVALID;
|
||||||
|
while (hb_set_next (original, &cp)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hb_set_destroy(original);
|
||||||
|
}
|
||||||
|
BENCHMARK(BM_SetIteration)
|
||||||
|
->Unit(benchmark::kMicrosecond)
|
||||||
|
->ArgsProduct({
|
||||||
|
benchmark::CreateRange(1 << 10, 1 << 16, 8), // Set size
|
||||||
|
benchmark::CreateDenseRange(2, 8, /*step=*/2) // Density
|
||||||
|
});
|
||||||
|
|
||||||
BENCHMARK_MAIN();
|
BENCHMARK_MAIN();
|
||||||
|
|
Loading…
Reference in New Issue