Commit e7e16f3d authored by Tom Jackson's avatar Tom Jackson Committed by Andrew Cox

Adding demonstrative test of O(n^2) string split case

Summary:
Even though the benchmark only keeps the first 10 lines, it gets slower the bigger the "file" is.

```
folly/gen/test/StringBenchmark.cpp              relative  time/iter  iters/s
----------------------------------------------------------------------------
Lines_Gen(1e3)                                               5.53us  180.94K
Lines_Gen(2e3)                                    66.43%     8.32us  120.21K
Lines_Gen(3e3)                                    48.26%    11.45us   87.33K
```

Test Plan: Benchmarks

Reviewed By: lesha@fb.com

Subscribers: folly-diffs@, yfeldblum

FB internal diff: D1823545

Tasks: 6155600

Signature: t1:1823545:1423023712:86fdb3dadbec44195e4b3596cf793cea80ae3a76
parent ad4a9ff7
......@@ -35,6 +35,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;
......@@ -212,6 +213,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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment