summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/benchmark/test/map_test.cc
diff options
context:
space:
mode:
author ImJezze <jezze@gmx.net>2016-03-12 12:31:13 +0100
committer ImJezze <jezze@gmx.net>2016-03-12 12:31:13 +0100
commita026a582f1a0ea8c1ede3acaddacef506ef3f3b0 (patch)
treee31573822f2359677de519f9f3b600d98e8764cd /3rdparty/benchmark/test/map_test.cc
parent477d2abd43984f076b7e45f5527591fa8fd0d241 (diff)
parentdcab55bf53b94713a6f72e9633f5101c8dd6c08c (diff)
Merge pull request #15 from mamedev/master
Sync to base master
Diffstat (limited to '3rdparty/benchmark/test/map_test.cc')
-rw-r--r--3rdparty/benchmark/test/map_test.cc58
1 files changed, 58 insertions, 0 deletions
diff --git a/3rdparty/benchmark/test/map_test.cc b/3rdparty/benchmark/test/map_test.cc
new file mode 100644
index 00000000000..5eccf8d39c4
--- /dev/null
+++ b/3rdparty/benchmark/test/map_test.cc
@@ -0,0 +1,58 @@
+#include "benchmark/benchmark.h"
+
+#include <cstdlib>
+#include <map>
+
+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));
+ }
+ return m;
+}
+
+} // namespace
+
+// Basic version.
+static void BM_MapLookup(benchmark::State& state) {
+ const int size = state.range_x();
+ while (state.KeepRunning()) {
+ state.PauseTiming();
+ std::map<int, int> m = ConstructRandomMap(size);
+ state.ResumeTiming();
+ for (int i = 0; i < size; ++i) {
+ benchmark::DoNotOptimize(m.find(rand() % size));
+ }
+ }
+ state.SetItemsProcessed(state.iterations() * size);
+}
+BENCHMARK(BM_MapLookup)->Range(1 << 3, 1 << 12);
+
+// Using fixtures.
+class MapFixture : public ::benchmark::Fixture {
+ public:
+ void SetUp(const ::benchmark::State& st) {
+ m = ConstructRandomMap(st.range_x());
+ }
+
+ void TearDown(const ::benchmark::State&) {
+ m.clear();
+ }
+
+ std::map<int, int> m;
+};
+
+BENCHMARK_DEFINE_F(MapFixture, Lookup)(benchmark::State& state) {
+ const int size = state.range_x();
+ while (state.KeepRunning()) {
+ for (int i = 0; i < size; ++i) {
+ benchmark::DoNotOptimize(m.find(rand() % size));
+ }
+ }
+ state.SetItemsProcessed(state.iterations() * size);
+}
+BENCHMARK_REGISTER_F(MapFixture, Lookup)->Range(1<<3, 1<<12);
+
+BENCHMARK_MAIN()