[libcxx] r336636 - Add new string benchmarks

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 9 21:11:22 PDT 2018


Author: ericwf
Date: Mon Jul  9 21:11:22 2018
New Revision: 336636

URL: http://llvm.org/viewvc/llvm-project?rev=336636&view=rev
Log:
Add new string benchmarks

Modified:
    libcxx/trunk/benchmarks/string.bench.cpp

Modified: libcxx/trunk/benchmarks/string.bench.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/benchmarks/string.bench.cpp?rev=336636&r1=336635&r2=336636&view=diff
==============================================================================
--- libcxx/trunk/benchmarks/string.bench.cpp (original)
+++ libcxx/trunk/benchmarks/string.bench.cpp Mon Jul  9 21:11:22 2018
@@ -46,4 +46,25 @@ static void BM_StringFindMatch2(benchmar
 }
 BENCHMARK(BM_StringFindMatch2)->Range(1, MAX_STRING_LEN / 4);
 
+static void BM_StringCtorDefault(benchmark::State &state) {
+  while (state.KeepRunning()) {
+    for (unsigned I=0; I < 1000; ++I) {
+      std::string Default;
+      benchmark::DoNotOptimize(Default.c_str());
+    }
+  }
+}
+BENCHMARK(BM_StringCtorDefault);
+
+static void BM_StringCtorCStr(benchmark::State &state) {
+  std::string Input = getRandomString(state.range(0));
+  const char *Str = Input.c_str();
+  benchmark::DoNotOptimize(Str);
+  while (state.KeepRunning()) {
+    std::string Tmp(Str);
+    benchmark::DoNotOptimize(Tmp.c_str());
+  }
+}
+BENCHMARK(BM_StringCtorCStr)->Arg(1)->Arg(8)->Range(16, MAX_STRING_LEN / 4);
+
 BENCHMARK_MAIN();




More information about the cfe-commits mailing list