From 5866ec05f5a2a613501095e1de64d641ad898021 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 29 Apr 2022 13:14:41 -0600 Subject: [PATCH] [benchmark-map] Remove rand() overhead from benchmark --- perf/benchmark-map.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/perf/benchmark-map.cc b/perf/benchmark-map.cc index 7ec891135..8f4eb1e80 100644 --- a/perf/benchmark-map.cc +++ b/perf/benchmark-map.cc @@ -29,11 +29,13 @@ static void BM_MapInsert(benchmark::State& state) { RandomMap(map_size, original); assert(hb_map_get_population(original) == map_size); + auto needle = map_size / 2; + auto v = 0; 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_set (original, needle++, v++); } hb_map_destroy(original); @@ -49,9 +51,11 @@ static void BM_MapLookup(benchmark::State& state) { RandomMap(map_size, original); assert(hb_map_get_population(original) == map_size); + auto needle = map_size / 2; + for (auto _ : state) { benchmark::DoNotOptimize( - hb_map_get (original, rand())); + hb_map_get (original, needle++)); } hb_map_destroy(original);