fix -Wunused-variable
[folly.git] / folly / gen / test / StringBenchmark.cpp
index fcc20d12fb496e496bcd3123da3052c775463eaf..96143b081ea63cae55993f67eb769896cd089298 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 #include <atomic>
+
 #include <glog/logging.h>
 
 #include <folly/Benchmark.h>
 #include <folly/String.h>
+#include <folly/container/Foreach.h>
 #include <folly/gen/Base.h>
 #include <folly/gen/String.h>
 
@@ -35,6 +38,7 @@ static vector<fbstring> testStrVector
   = seq(1, testSize.load())
   | eachTo<fbstring>()
   | as<vector>();
+static auto testFileContent = from(testStrVector) | unsplit('\n');
 
 const char* const kLine = "The quick brown fox jumped over the lazy dog.\n";
 const size_t kLineCount = 10000;
@@ -59,7 +63,7 @@ void initStringResplitterBenchmark() {
 
 size_t len(folly::StringPiece s) { return s.size(); }
 
-}  // namespace
+} // namespace
 
 BENCHMARK(StringResplitter_Big, iters) {
   size_t s = 0;
@@ -169,7 +173,6 @@ BENCHMARK_RELATIVE(StringUnsplit_Old_ReusedBuffer, iters) {
 
 BENCHMARK_RELATIVE(StringUnsplit_Gen, iters) {
   size_t s = 0;
-  StringPiece line(kLine);
   while (iters--) {
     fbstring joined = from(testStrVector) | unsplit(',');
     s += joined.size();
@@ -212,6 +215,20 @@ BENCHMARK_RELATIVE_PARAM(StringUnsplit_Gen, 2000)
 BENCHMARK_RELATIVE_PARAM(StringUnsplit_Gen, 4000)
 BENCHMARK_RELATIVE_PARAM(StringUnsplit_Gen, 8000)
 
+BENCHMARK_DRAW_LINE()
+void Lines_Gen(size_t iters, int joinSize) {
+  size_t s = 0;
+  StringPiece content = testFileContent;
+  for (size_t i = 0; i < iters; ++i) {
+    s += lines(content.subpiece(0, joinSize)) | take(100) | count;
+  }
+  folly::doNotOptimizeAway(s);
+}
+
+BENCHMARK_PARAM(Lines_Gen, 1e3)
+BENCHMARK_RELATIVE_PARAM(Lines_Gen, 2e3)
+BENCHMARK_RELATIVE_PARAM(Lines_Gen, 3e3)
+
 BENCHMARK_DRAW_LINE()
 
 fbstring records