From b5e51ce63898420cccd55f0cfd5c4bddd16845e3 Mon Sep 17 00:00:00 2001 From: Soren Lassen Date: Sun, 6 Jan 2013 22:37:22 -0800 Subject: [PATCH] Make FindFirstOf[Offset]Range benchmarks traverse haystack. Summary: Doh. Thank you Mike for pointing this out. Renamed "needle" to "needles" and added DCHECK to clarify the semantics. Test Plan: Ran benchmark. Reviewed By: mmcurtiss@fb.com FB internal diff: D672154 --- folly/test/RangeFindBenchmark.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/folly/test/RangeFindBenchmark.cpp b/folly/test/RangeFindBenchmark.cpp index 5f58db0a..654e00b2 100644 --- a/folly/test/RangeFindBenchmark.cpp +++ b/folly/test/RangeFindBenchmark.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2012 Facebook, Inc. + * Copyright 2013 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,9 +62,10 @@ BENCHMARK_DRAW_LINE(); BENCHMARK(FindFirstOfRange, n) { StringPiece haystack(str); - folly::StringPiece needle("ab"); + folly::StringPiece needles("bc"); + DCHECK_EQ(haystack.size() - 1, haystack.find_first_of(needles)); // it works! FOR_EACH_RANGE (i, 0, n) { - doNotOptimizeAway(haystack.find_first_of(needle)); + doNotOptimizeAway(haystack.find_first_of(needles)); char x = haystack[0]; doNotOptimizeAway(&x); } @@ -72,10 +73,11 @@ BENCHMARK(FindFirstOfRange, n) { BENCHMARK(FindFirstOfOffsetRange, n) { StringPiece haystack(str); - folly::StringPiece needle("ab"); + folly::StringPiece needles("bc"); + DCHECK_EQ(haystack.size() - 1, haystack.find_first_of(needles, 1)); // works! FOR_EACH_RANGE (i, 0, n) { - size_t pos = i / 2; // not a constant to prevent optimization - doNotOptimizeAway(haystack.find_first_of(needle, pos)); + size_t pos = i % 2; // not a constant to prevent optimization + doNotOptimizeAway(haystack.find_first_of(needles, pos)); char x = haystack[0]; doNotOptimizeAway(&x); } @@ -84,7 +86,7 @@ BENCHMARK(FindFirstOfOffsetRange, n) { int main(int argc, char** argv) { google::ParseCommandLineFlags(&argc, &argv, true); - for (int len : {10, 256, 10*1024, 10*1024*1024}) { + for (int len : {1, 10, 256, 10*1024, 10*1024*1024}) { initStr(len); runBenchmarks(); } -- 2.34.1