| 55 | |
| 56 | template <typename Cache, typename Key, typename Value> |
| 57 | static void BenchmarkCacheLookups(benchmark::State& state, const std::vector<Key>& keys, |
| 58 | const std::vector<Value>& values) { |
| 59 | const int32_t nitems = static_cast<int32_t>(keys.size()); |
| 60 | Cache cache(nitems); |
| 61 | for (int32_t i = 0; i < nitems; ++i) { |
| 62 | cache.Replace(keys[i], values[i]); |
| 63 | } |
| 64 | |
| 65 | for (auto _ : state) { |
| 66 | int64_t nfinds = 0; |
| 67 | for (const auto& key : keys) { |
| 68 | nfinds += (cache.Find(key) != nullptr); |
| 69 | } |
| 70 | benchmark::DoNotOptimize(nfinds); |
| 71 | ARROW_CHECK_EQ(nfinds, nitems); |
| 72 | } |
| 73 | state.SetItemsProcessed(state.iterations() * nitems); |
| 74 | } |
| 75 | |
| 76 | static void LruCacheLookup(benchmark::State& state) { |
| 77 | const auto keys = MakeStrings(kCacheSize, state.range(0)); |