[libcxx] r276552 - Start adding benchmarks for vector

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 23 23:51:55 PDT 2016


Author: ericwf
Date: Sun Jul 24 01:51:55 2016
New Revision: 276552

URL: http://llvm.org/viewvc/llvm-project?rev=276552&view=rev
Log:
Start adding benchmarks for vector

Added:
    libcxx/trunk/benchmarks/vector_operations.bench.cpp
Modified:
    libcxx/trunk/benchmarks/ContainerBenchmarks.hpp

Modified: libcxx/trunk/benchmarks/ContainerBenchmarks.hpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/benchmarks/ContainerBenchmarks.hpp?rev=276552&r1=276551&r2=276552&view=diff
==============================================================================
--- libcxx/trunk/benchmarks/ContainerBenchmarks.hpp (original)
+++ libcxx/trunk/benchmarks/ContainerBenchmarks.hpp Sun Jul 24 01:51:55 2016
@@ -7,6 +7,18 @@
 
 namespace ContainerBenchmarks {
 
+
+template <class Container, class GenInputs>
+void BM_ConstructIterIter(benchmark::State& st, Container, GenInputs gen) {
+    auto in = gen(st.range_x());
+    const auto end = in.end();
+    benchmark::DoNotOptimize(&in);
+    while (st.KeepRunning()) {
+        Container c(in.begin(), in.end());
+        benchmark::DoNotOptimize(c.data());
+    }
+}
+
 template <class Container, class GenInputs>
 void BM_InsertValue(benchmark::State& st, Container c, GenInputs gen) {
     auto in = gen(st.range_x());
@@ -93,7 +105,6 @@ static void BM_FindRehash(benchmark::Sta
         }
         benchmark::ClobberMemory();
     }
-
 }
 
 } // end namespace ContainerBenchmarks

Added: libcxx/trunk/benchmarks/vector_operations.bench.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/benchmarks/vector_operations.bench.cpp?rev=276552&view=auto
==============================================================================
--- libcxx/trunk/benchmarks/vector_operations.bench.cpp (added)
+++ libcxx/trunk/benchmarks/vector_operations.bench.cpp Sun Jul 24 01:51:55 2016
@@ -0,0 +1,32 @@
+#include <vector>
+#include <functional>
+#include <cstdint>
+#include <cstdlib>
+#include <cstring>
+
+#include "benchmark/benchmark_api.h"
+
+#include "ContainerBenchmarks.hpp"
+#include "GenerateInput.hpp"
+
+using namespace ContainerBenchmarks;
+
+constexpr std::size_t TestNumInputs = 1024;
+
+BENCHMARK_CAPTURE(BM_ConstructIterIter,
+  vector_char,
+  std::vector<char>{},
+  getRandomIntegerInputs<char>)->Arg(TestNumInputs);
+
+BENCHMARK_CAPTURE(BM_ConstructIterIter,
+  vector_size_t,
+  std::vector<size_t>{},
+  getRandomIntegerInputs<size_t>)->Arg(TestNumInputs);
+
+BENCHMARK_CAPTURE(BM_ConstructIterIter,
+  vector_string,
+  std::vector<std::string>{},
+  getRandomStringInputs)->Arg(TestNumInputs);
+
+
+BENCHMARK_MAIN()




More information about the cfe-commits mailing list