Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
one more simple folly::join optimization
Summary:
Before:

_bin/folly/test/string_test --benchmark --bm_regex=join --bm_min_usec=1000000
============================================================================
folly/test/StringTest.cpp                       relative  time/iter  iters/s
============================================================================
joinCharStr                                                  3.59us  278.29K
joinStrStr                                                   4.44us  225.09K
joinInt                                                     10.55us   94.76K
============================================================================

And after:

_bin/folly/test/string_test --benchmark --bm_regex=join --bm_min_usec=1000000
============================================================================
folly/test/StringTest.cpp                       relative  time/iter  iters/s
============================================================================
joinCharStr                                                  3.61us  277.01K
joinStrStr                                                   3.77us  264.97K
joinInt                                                      9.92us  100.81K
============================================================================

Test Plan: unittests, benchmark

Reviewed By: tudorb@fb.com

FB internal diff: D552364
  • Loading branch information
philippv authored and tudor committed Aug 26, 2012
1 parent ff25e3b commit 5df0c97
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions folly/String-inl.h
Expand Up @@ -312,6 +312,11 @@ void internalJoinAppend(Delim delimiter,
Iterator end,
String& output) {
assert(begin != end);
if (std::is_same<Delim, StringPiece>::value &&
delimSize(delimiter) == 1) {
internalJoinAppend(delimFront(delimiter), begin, end, output);
return;
}
toAppend(*begin, &output);
while (++begin != end) {
toAppend(delimiter, *begin, &output);
Expand Down
11 changes: 10 additions & 1 deletion folly/test/StringTest.cpp
Expand Up @@ -761,7 +761,16 @@ BENCHMARK(boost_splitOnSingleChar, iters) {
}
}

BENCHMARK(joinStr, iters) {
BENCHMARK(joinCharStr, iters) {
static const std::vector<std::string> input = {
"one", "two", "three", "four", "five", "six", "seven" };
for (int i = 0; i < iters << 4; ++i) {
std::string output;
folly::join(':', input, output);
}
}

BENCHMARK(joinStrStr, iters) {
static const std::vector<std::string> input = {
"one", "two", "three", "four", "five", "six", "seven" };
for (int i = 0; i < iters << 4; ++i) {
Expand Down

0 comments on commit 5df0c97

Please sign in to comment.