Skip to content

Commit

Permalink
map_test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dmah42 committed Mar 8, 2018
1 parent f07d439 commit a721ca9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions test/map_test.cc
Expand Up @@ -8,7 +8,7 @@ namespace {
std::map<int, int> ConstructRandomMap(int size) {
std::map<int, int> m;
for (int i = 0; i < size; ++i) {
m.insert(std::make_pair(rand() % size, rand() % size));
m.insert(std::make_pair(std::rand() % size, std::rand() % size));
}
return m;
}
Expand All @@ -17,14 +17,14 @@ std::map<int, int> ConstructRandomMap(int size) {

// Basic version.
static void BM_MapLookup(benchmark::State& state) {
const int size = state.range(0);
const int size = static_cast<int>(state.range(0));
std::map<int, int> m;
for (auto _ : state) {
state.PauseTiming();
m = ConstructRandomMap(size);
state.ResumeTiming();
for (int i = 0; i < size; ++i) {
benchmark::DoNotOptimize(m.find(rand() % size));
benchmark::DoNotOptimize(m.find(std::rand() % size));
}
}
state.SetItemsProcessed(state.iterations() * size);
Expand All @@ -35,7 +35,7 @@ BENCHMARK(BM_MapLookup)->Range(1 << 3, 1 << 12);
class MapFixture : public ::benchmark::Fixture {
public:
void SetUp(const ::benchmark::State& st) {
m = ConstructRandomMap(st.range(0));
m = ConstructRandomMap(static_cast<int>(st.range(0)));
}

void TearDown(const ::benchmark::State&) { m.clear(); }
Expand All @@ -44,10 +44,10 @@ class MapFixture : public ::benchmark::Fixture {
};

BENCHMARK_DEFINE_F(MapFixture, Lookup)(benchmark::State& state) {
const int size = state.range(0);
const int size = static_cast<int>(state.range(0));
for (auto _ : state) {
for (int i = 0; i < size; ++i) {
benchmark::DoNotOptimize(m.find(rand() % size));
benchmark::DoNotOptimize(m.find(std::rand() % size));
}
}
state.SetItemsProcessed(state.iterations() * size);
Expand Down

0 comments on commit a721ca9

Please sign in to comment.