[perf] Add the start of a benchmark for set operations.
This commit is contained in:
parent
e8b40c7a09
commit
cef64b947d
|
@ -0,0 +1,49 @@
|
|||
#include "benchmark/benchmark.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include "hb.h"
|
||||
|
||||
void RandomSet(unsigned size, unsigned max_value, hb_set_t* out) {
|
||||
hb_set_clear(out);
|
||||
|
||||
srand(size * max_value);
|
||||
for (unsigned i = 0; i < size; i++) {
|
||||
while (true) {
|
||||
unsigned next = rand() % max_value;
|
||||
if (hb_set_has (out, next)) continue;
|
||||
|
||||
hb_set_add(out, next);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void BM_SetInsert(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) {
|
||||
state.PauseTiming();
|
||||
hb_set_t* data = hb_set_copy(original);
|
||||
state.ResumeTiming();
|
||||
|
||||
hb_set_add(data, rand() % max_value);
|
||||
|
||||
state.PauseTiming();
|
||||
hb_set_destroy(data);
|
||||
state.ResumeTiming();
|
||||
}
|
||||
|
||||
hb_set_destroy(original);
|
||||
}
|
||||
BENCHMARK(BM_SetInsert)
|
||||
->ArgsProduct({
|
||||
benchmark::CreateRange(1 << 10, 1 << 16, 8), // Set size
|
||||
benchmark::CreateDenseRange(2, 8, /*step=*/2) // Density
|
||||
});
|
||||
|
||||
BENCHMARK_MAIN();
|
|
@ -19,3 +19,18 @@ benchmark('perf', executable('perf', 'perf.cc',
|
|||
link_with: [libharfbuzz],
|
||||
install: false,
|
||||
), workdir: meson.current_source_dir() / '..', timeout: 100)
|
||||
|
||||
|
||||
benchmark('benchmark-set', executable('benchmark-set', 'benchmark-set.cc',
|
||||
dependencies: [
|
||||
google_benchmark_dep, freetype_dep,
|
||||
|
||||
# the last two, thread and dl, aren't nice as ttf-parser isn't no_std yet
|
||||
# https://github.com/RazrFalcon/ttf-parser/issues/29
|
||||
ttf_parser_dep, thread_dep, cpp.find_library('dl'),
|
||||
],
|
||||
cpp_args: ttf_parser_dep.found() ? ['-DHAVE_TTFPARSER'] : [],
|
||||
include_directories: [incconfig, incsrc],
|
||||
link_with: [libharfbuzz],
|
||||
install: false,
|
||||
), workdir: meson.current_source_dir() / '..', timeout: 100)
|
||||
|
|
Loading…
Reference in New Issue