summaryrefslogtreecommitdiffstats
path: root/llvm/utils/benchmark/test/map_test.cc
diff options
context:
space:
mode:
authorKirill Bobyrev <kbobyrev.opensource@gmail.com>2018-08-28 09:42:41 +0000
committerKirill Bobyrev <kbobyrev.opensource@gmail.com>2018-08-28 09:42:41 +0000
commit0addd170ab0880941fa4089c2717f3f3a0e4e25a (patch)
tree71d7a249b508800e1be898aa7cb789d4ed7c8f2b /llvm/utils/benchmark/test/map_test.cc
parent0c4b84e2df541b42238b1e15d2abb5ee4b262402 (diff)
downloadbcm5719-llvm-0addd170ab0880941fa4089c2717f3f3a0e4e25a.tar.gz
bcm5719-llvm-0addd170ab0880941fa4089c2717f3f3a0e4e25a.zip
Pull google/benchmark library to the LLVM tree
This patch pulls google/benchmark v1.4.1 into the LLVM tree so that any project could use it for benchmark generation. A dummy benchmark is added to `llvm/benchmarks/DummyYAML.cpp` to validate the correctness of the build process. The current version does not utilize LLVM LNT and LLVM CMake infrastructure, but that might be sufficient for most users. Two introduced CMake variables: * `LLVM_INCLUDE_BENCHMARKS` (`ON` by default) generates benchmark targets * `LLVM_BUILD_BENCHMARKS` (`OFF` by default) adds generated benchmark targets to the list of default LLVM targets (i.e. if `ON` benchmarks will be built upon standard build invocation, e.g. `ninja` or `make` with no specific targets) List of modifications: * `BENCHMARK_ENABLE_TESTING` is disabled * `BENCHMARK_ENABLE_EXCEPTIONS` is disabled * `BENCHMARK_ENABLE_INSTALL` is disabled * `BENCHMARK_ENABLE_GTEST_TESTS` is disabled * `BENCHMARK_DOWNLOAD_DEPENDENCIES` is disabled Original discussion can be found here: http://lists.llvm.org/pipermail/llvm-dev/2018-August/125023.html Reviewed by: dberris, lebedev.ri Subscribers: ilya-biryukov, ioeric, EricWF, lebedev.ri, srhines, dschuff, mgorny, krytarowski, fedor.sergeev, mgrang, jfb, llvm-commits Differential Revision: https://reviews.llvm.org/D50894 llvm-svn: 340809
Diffstat (limited to 'llvm/utils/benchmark/test/map_test.cc')
-rw-r--r--llvm/utils/benchmark/test/map_test.cc57
1 files changed, 57 insertions, 0 deletions
diff --git a/llvm/utils/benchmark/test/map_test.cc b/llvm/utils/benchmark/test/map_test.cc
new file mode 100644
index 00000000000..dbf7982a368
--- /dev/null
+++ b/llvm/utils/benchmark/test/map_test.cc
@@ -0,0 +1,57 @@
+#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(std::rand() % size, std::rand() % size));
+ }
+ return m;
+}
+
+} // namespace
+
+// Basic version.
+static void BM_MapLookup(benchmark::State& state) {
+ 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(std::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(static_cast<int>(st.range(0)));
+ }
+
+ void TearDown(const ::benchmark::State&) { m.clear(); }
+
+ std::map<int, int> m;
+};
+
+BENCHMARK_DEFINE_F(MapFixture, Lookup)(benchmark::State& state) {
+ const int size = static_cast<int>(state.range(0));
+ for (auto _ : state) {
+ for (int i = 0; i < size; ++i) {
+ benchmark::DoNotOptimize(m.find(std::rand() % size));
+ }
+ }
+ state.SetItemsProcessed(state.iterations() * size);
+}
+BENCHMARK_REGISTER_F(MapFixture, Lookup)->Range(1 << 3, 1 << 12);
+
+BENCHMARK_MAIN();
OpenPOWER on IntegriCloud