Commit 6a1addcc authored by Chip Turner's avatar Chip Turner Committed by JoelMarcey

Improve benchmarking around stringPrintf functions

Summary:
Before optimizing this code, it is better to measure different
aspects of it to ensure improvements are worth it and don'tintroduce
other regressions.

This adds a new benchmark as well as parameterizes an old one.

Test Plan: run it

Reviewed By: lovro@fb.com

Subscribers: lins, anca, folly-diffs@

FB internal diff: D1733760

Tasks: 5735468

Signature: t1:1733760:1418313479:9f572d5a4cf014bd266d91d0f7a75407d1514f65
parent 61e26ae9
...@@ -146,13 +146,36 @@ TEST(StringPrintf, oldStringAppendf) { ...@@ -146,13 +146,36 @@ TEST(StringPrintf, oldStringAppendf) {
EXPECT_EQ(string("helloa/b/c/d"), s); EXPECT_EQ(string("helloa/b/c/d"), s);
} }
BENCHMARK(new_stringPrintfSmall, iters) { // A simple benchmark that tests various output sizes for a simple
// input; the goal is to measure the output buffer resize code cost.
void stringPrintfOutputSize(int iters, int param) {
string buffer;
BENCHMARK_SUSPEND { buffer.resize(param, 'x'); }
for (int64_t i = 0; i < iters; ++i) { for (int64_t i = 0; i < iters; ++i) {
int32_t x = int32_t(i); string s = stringPrintf("msg: %d, %d, %s", 10, 20, buffer.c_str());
int32_t y = int32_t(i + 1); }
string s = }
stringPrintf("msg msg msg msg msg msg msg msg: %d, %d, %s",
x, y, "hello"); // The first few of these tend to fit in the inline buffer, while the
// subsequent ones cross that limit, trigger a second vsnprintf, and
// exercise a different codepath.
BENCHMARK_PARAM(stringPrintfOutputSize, 1)
BENCHMARK_PARAM(stringPrintfOutputSize, 4)
BENCHMARK_PARAM(stringPrintfOutputSize, 16)
BENCHMARK_PARAM(stringPrintfOutputSize, 64)
BENCHMARK_PARAM(stringPrintfOutputSize, 256)
BENCHMARK_PARAM(stringPrintfOutputSize, 1024)
// Benchmark simple stringAppendf behavior to show a pathology Lovro
// reported (t5735468).
BENCHMARK(stringPrintfAppendfBenchmark, iters) {
for (unsigned int i = 0; i < iters; ++i) {
string s;
BENCHMARK_SUSPEND { s.reserve(300000); }
for (int j = 0; j < 300000; ++j) {
stringAppendf(&s, "%d", 1);
}
} }
} }
......
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