[perf] Add map benchmarks.
This commit is contained in:
parent
057ec2c953
commit
fc2027bf07
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Benchmarks for hb_map_t operations.
|
||||
*/
|
||||
#include "benchmark/benchmark.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include "hb.h"
|
||||
|
||||
void RandomMap(unsigned size, hb_map_t* out) {
|
||||
hb_map_clear(out);
|
||||
|
||||
srand(size);
|
||||
for (unsigned i = 0; i < size; i++) {
|
||||
while (true) {
|
||||
hb_codepoint_t next = rand();
|
||||
if (hb_map_has (out, next)) continue;
|
||||
|
||||
hb_map_set (out, next, rand ());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Insert a single value into map of varying sizes. */
|
||||
static void BM_MapInsert(benchmark::State& state) {
|
||||
unsigned map_size = state.range(0);
|
||||
|
||||
hb_map_t* original = hb_map_create ();
|
||||
RandomMap(map_size, original);
|
||||
assert(hb_map_get_population(original) == map_size);
|
||||
|
||||
for (auto _ : state) {
|
||||
// TODO(garretrieger): create a copy of the original map.
|
||||
// Needs a hb_map_copy(..) in public api.
|
||||
|
||||
hb_map_set (original, rand (), rand ());
|
||||
}
|
||||
|
||||
hb_map_destroy(original);
|
||||
}
|
||||
BENCHMARK(BM_MapInsert)
|
||||
->Range(1 << 10, 1 << 16);
|
||||
|
||||
/* Single value lookup on map of various sizes. */
|
||||
static void BM_MapLookup(benchmark::State& state) {
|
||||
unsigned map_size = state.range(0);
|
||||
|
||||
hb_map_t* original = hb_map_create ();
|
||||
RandomMap(map_size, original);
|
||||
assert(hb_map_get_population(original) == map_size);
|
||||
|
||||
for (auto _ : state) {
|
||||
benchmark::DoNotOptimize(
|
||||
hb_map_get (original, rand()));
|
||||
}
|
||||
|
||||
hb_map_destroy(original);
|
||||
}
|
||||
BENCHMARK(BM_MapLookup)
|
||||
->Range(1 << 10, 1 << 16); // Set size
|
||||
|
||||
|
||||
BENCHMARK_MAIN();
|
|
@ -1,3 +1,6 @@
|
|||
/*
|
||||
* Benchmarks for hb_set_t operations.
|
||||
*/
|
||||
#include "benchmark/benchmark.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
@ -18,6 +21,8 @@ void RandomSet(unsigned size, unsigned max_value, hb_set_t* out) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO(garretrieger): benchmark union/subtract/intersection etc.
|
||||
|
||||
/* Insert a single value into set of varying sizes. */
|
||||
static void BM_SetInsert(benchmark::State& state) {
|
||||
unsigned set_size = state.range(0);
|
||||
|
|
|
@ -23,13 +23,19 @@ benchmark('perf', executable('perf', 'perf.cc',
|
|||
|
||||
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'),
|
||||
google_benchmark_dep,
|
||||
],
|
||||
cpp_args: ttf_parser_dep.found() ? ['-DHAVE_TTFPARSER'] : [],
|
||||
cpp_args: [],
|
||||
include_directories: [incconfig, incsrc],
|
||||
link_with: [libharfbuzz],
|
||||
install: false,
|
||||
), workdir: meson.current_source_dir() / '..', timeout: 100)
|
||||
|
||||
benchmark('benchmark-map', executable('benchmark-map', 'benchmark-map.cc',
|
||||
dependencies: [
|
||||
google_benchmark_dep,
|
||||
],
|
||||
cpp_args: [],
|
||||
include_directories: [incconfig, incsrc],
|
||||
link_with: [libharfbuzz],
|
||||
install: false,
|
||||
|
|
Loading…
Reference in New Issue