proxygen
RangeFindBenchmark.cpp File Reference
#include <folly/Range.h>
#include <algorithm>
#include <iostream>
#include <random>
#include <string>
#include <folly/Benchmark.h>
#include <folly/container/Foreach.h>

Go to the source code of this file.

Functions

 BENCHMARK (FindSingleCharMemchr, n)
 
 BENCHMARK_RELATIVE (FindSingleCharRange, n)
 
 BENCHMARK_DRAW_LINE ()
 
template<class Func >
void countHits (Func func, size_t n)
 
template<class Func >
void findFirstOfRange (StringPiece needles, Func func, size_t n)
 
 BENCHMARK (FindFirstOf1NeedlesBase, n)
 
 BENCHMARK_RELATIVE (FindFirstOf1NeedlesNoSSE, n)
 
 BENCHMARK_RELATIVE (FindFirstOf1NeedlesStd, n)
 
 BENCHMARK_RELATIVE (FindFirstOf1NeedlesByteSet, n)
 
 BENCHMARK_RELATIVE (FindFirstOf1NeedlesBitSet, n)
 
 BENCHMARK (FindFirstOf2NeedlesBase, n)
 
 BENCHMARK_RELATIVE (FindFirstOf2NeedlesNoSSE, n)
 
 BENCHMARK_RELATIVE (FindFirstOf2NeedlesStd, n)
 
 BENCHMARK_RELATIVE (FindFirstOf2NeedlesByteSet, n)
 
 BENCHMARK_RELATIVE (FindFirstOf2NeedlesBitSet, n)
 
 BENCHMARK (FindFirstOf4NeedlesBase, n)
 
 BENCHMARK_RELATIVE (FindFirstOf4NeedlesNoSSE, n)
 
 BENCHMARK_RELATIVE (FindFirstOf4NeedlesStd, n)
 
 BENCHMARK_RELATIVE (FindFirstOf4NeedlesByteSet, n)
 
 BENCHMARK_RELATIVE (FindFirstOf4NeedlesBitSet, n)
 
 BENCHMARK (FindFirstOf8NeedlesBase, n)
 
 BENCHMARK_RELATIVE (FindFirstOf8NeedlesNoSSE, n)
 
 BENCHMARK_RELATIVE (FindFirstOf8NeedlesStd, n)
 
 BENCHMARK_RELATIVE (FindFirstOf8NeedlesByteSet, n)
 
 BENCHMARK_RELATIVE (FindFirstOf8NeedlesBitSet, n)
 
 BENCHMARK (FindFirstOf16NeedlesBase, n)
 
 BENCHMARK_RELATIVE (FindFirstOf16NeedlesNoSSE, n)
 
 BENCHMARK_RELATIVE (FindFirstOf16NeedlesStd, n)
 
 BENCHMARK_RELATIVE (FindFirstOf16NeedlesByteSet, n)
 
 BENCHMARK_RELATIVE (FindFirstOf16NeedlesBitSet, n)
 
 BENCHMARK (FindFirstOf32NeedlesBase, n)
 
 BENCHMARK_RELATIVE (FindFirstOf32NeedlesNoSSE, n)
 
 BENCHMARK_RELATIVE (FindFirstOf32NeedlesStd, n)
 
 BENCHMARK_RELATIVE (FindFirstOf32NeedlesByteSet, n)
 
 BENCHMARK_RELATIVE (FindFirstOf32NeedlesBitSet, n)
 
 BENCHMARK (FindFirstOf64NeedlesBase, n)
 
 BENCHMARK_RELATIVE (FindFirstOf64NeedlesNoSSE, n)
 
 BENCHMARK_RELATIVE (FindFirstOf64NeedlesStd, n)
 
 BENCHMARK_RELATIVE (FindFirstOf64NeedlesByteSet, n)
 
 BENCHMARK_RELATIVE (FindFirstOf64NeedlesBitSet, n)
 
template<class Func >
void findFirstOfRandom (Func func, size_t iters)
 
 BENCHMARK (FindFirstOfRandomBase, n)
 
 BENCHMARK_RELATIVE (FindFirstOfRandomNoSSE, n)
 
 BENCHMARK_RELATIVE (FindFirstOfRandomStd, n)
 
 BENCHMARK_RELATIVE (FindFirstOfRandomByteSet, n)
 
 BENCHMARK_RELATIVE (FindFirstOfRandomBitSet, n)
 
 BENCHMARK (CountDelimsBase, n)
 
 BENCHMARK_RELATIVE (CountDelimsNoSSE, n)
 
 BENCHMARK_RELATIVE (CountDelimsStd, n)
 
 BENCHMARK_RELATIVE (CountDelimsByteSet, n)
 
 BENCHMARK_RELATIVE (CountDelimsBitSet, n)
 
 BENCHMARK (FindFirstOfOffsetRange, n)
 
int main (int argc, char **argv)
 

Variables

const string delims1 = "b"
 
const string delims2 = "bc"
 
const string delims4 = "bcde"
 
const string delims8 = "0123456b"
 
const string delims16 = "0123456789bcdefg"
 
const string delims32 = "!bcdefghijklmnopqrstuvwxyz_012345"
 
const string delims64
 

Function Documentation

BENCHMARK ( FindSingleCharMemchr  ,
 
)

Definition at line 116 of file RangeFindBenchmark.cpp.

References folly::doNotOptimizeAway(), folly::Range< Iter >::find(), FOR_EACH_RANGE, and i.

116  {
117  StringPiece haystack(str);
118  FOR_EACH_RANGE (i, 0, n) {
119  doNotOptimizeAway(haystack.find('b'));
120  char x = haystack[0];
121  doNotOptimizeAway(&x);
122  }
123 }
Definition: InvokeTest.cpp:58
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( FindFirstOf1NeedlesBase  ,
 
)

Definition at line 164 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of().

164  {
166 }
void findFirstOfRange(StringPiece needles, Func func, size_t n)
size_t qfind_first_byte_of(const StringPiece haystack, const StringPiece needles)
Definition: Range.h:1349
const string delims1
BENCHMARK ( FindFirstOf2NeedlesBase  ,
 
)

Definition at line 188 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of().

188  {
190 }
const string delims2
void findFirstOfRange(StringPiece needles, Func func, size_t n)
size_t qfind_first_byte_of(const StringPiece haystack, const StringPiece needles)
Definition: Range.h:1349
BENCHMARK ( FindFirstOf4NeedlesBase  ,
 
)

Definition at line 212 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of().

212  {
214 }
void findFirstOfRange(StringPiece needles, Func func, size_t n)
size_t qfind_first_byte_of(const StringPiece haystack, const StringPiece needles)
Definition: Range.h:1349
const string delims4
BENCHMARK ( FindFirstOf8NeedlesBase  ,
 
)

Definition at line 236 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of().

236  {
238 }
void findFirstOfRange(StringPiece needles, Func func, size_t n)
const string delims8
size_t qfind_first_byte_of(const StringPiece haystack, const StringPiece needles)
Definition: Range.h:1349
BENCHMARK ( FindFirstOf16NeedlesBase  ,
 
)

Definition at line 260 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of().

260  {
262 }
const string delims16
void findFirstOfRange(StringPiece needles, Func func, size_t n)
size_t qfind_first_byte_of(const StringPiece haystack, const StringPiece needles)
Definition: Range.h:1349
BENCHMARK ( FindFirstOf32NeedlesBase  ,
 
)

Definition at line 284 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of().

284  {
286 }
void findFirstOfRange(StringPiece needles, Func func, size_t n)
size_t qfind_first_byte_of(const StringPiece haystack, const StringPiece needles)
Definition: Range.h:1349
const string delims32
BENCHMARK ( FindFirstOf64NeedlesBase  ,
 
)

Definition at line 310 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of().

310  {
312 }
void findFirstOfRange(StringPiece needles, Func func, size_t n)
size_t qfind_first_byte_of(const StringPiece haystack, const StringPiece needles)
Definition: Range.h:1349
const string delims64
BENCHMARK ( FindFirstOfRandomBase  ,
 
)

Definition at line 341 of file RangeFindBenchmark.cpp.

References findFirstOfRandom(), and folly::detail::qfind_first_byte_of().

341  {
343 }
size_t qfind_first_byte_of(const StringPiece haystack, const StringPiece needles)
Definition: Range.h:1349
void findFirstOfRandom(Func func, size_t iters)
BENCHMARK ( CountDelimsBase  ,
 
)

Definition at line 363 of file RangeFindBenchmark.cpp.

References countHits(), and folly::detail::qfind_first_byte_of().

363  {
365 }
void countHits(Func func, size_t n)
size_t qfind_first_byte_of(const StringPiece haystack, const StringPiece needles)
Definition: Range.h:1349
BENCHMARK ( FindFirstOfOffsetRange  ,
 
)

Definition at line 385 of file RangeFindBenchmark.cpp.

References folly::BENCHMARK_DRAW_LINE(), folly::doNotOptimizeAway(), folly::Range< Iter >::find_first_of(), FOR_EACH_RANGE, i, and folly::Range< Iter >::size().

385  {
386  StringPiece haystack(str);
387  folly::StringPiece needles("bc");
388  DCHECK_EQ(haystack.size() - 1, haystack.find_first_of(needles, 1)); // works!
389  FOR_EACH_RANGE (i, 0, n) {
390  size_t pos = i % 2; // not a constant to prevent optimization
391  doNotOptimizeAway(haystack.find_first_of(needles, pos));
392  char x = haystack[0];
393  doNotOptimizeAway(&x);
394  }
395 }
Definition: InvokeTest.cpp:58
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK_DRAW_LINE ( )
BENCHMARK_RELATIVE ( FindSingleCharRange  ,
 
)

Definition at line 125 of file RangeFindBenchmark.cpp.

References folly::BENCHMARK_DRAW_LINE(), c, folly::doNotOptimizeAway(), folly::Range< Iter >::find(), FOR_EACH_RANGE, i, and needle.

125  {
126  const char c = 'b';
127  StringPiece haystack(str);
128  folly::StringPiece needle(&c, &c + 1);
129  FOR_EACH_RANGE (i, 0, n) {
130  doNotOptimizeAway(haystack.find(needle));
131  char x = haystack[0];
132  doNotOptimizeAway(&x);
133  }
134 }
const string needle
Definition: InvokeTest.cpp:58
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
char c
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK_RELATIVE ( FindFirstOf1NeedlesNoSSE  ,
 
)

Definition at line 168 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_nosse().

168  {
170 }
void findFirstOfRange(StringPiece needles, Func func, size_t n)
size_t qfind_first_byte_of_nosse(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.h:92
const string delims1
BENCHMARK_RELATIVE ( FindFirstOf1NeedlesStd  ,
 
)

Definition at line 172 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_std().

172  {
174 }
size_t qfind_first_byte_of_std(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.h:72
void findFirstOfRange(StringPiece needles, Func func, size_t n)
const string delims1
BENCHMARK_RELATIVE ( FindFirstOf1NeedlesByteSet  ,
 
)

Definition at line 176 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_byteset().

176  {
178 }
size_t qfind_first_byte_of_byteset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:42
void findFirstOfRange(StringPiece needles, Func func, size_t n)
const string delims1
BENCHMARK_RELATIVE ( FindFirstOf1NeedlesBitSet  ,
 
)

Definition at line 180 of file RangeFindBenchmark.cpp.

References folly::BENCHMARK_DRAW_LINE(), findFirstOfRange(), and folly::detail::qfind_first_byte_of_bitset().

180  {
182 }
void findFirstOfRange(StringPiece needles, Func func, size_t n)
const string delims1
size_t qfind_first_byte_of_bitset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:27
BENCHMARK_RELATIVE ( FindFirstOf2NeedlesNoSSE  ,
 
)

Definition at line 192 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_nosse().

192  {
194 }
const string delims2
void findFirstOfRange(StringPiece needles, Func func, size_t n)
size_t qfind_first_byte_of_nosse(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.h:92
BENCHMARK_RELATIVE ( FindFirstOf2NeedlesStd  ,
 
)

Definition at line 196 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_std().

196  {
198 }
size_t qfind_first_byte_of_std(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.h:72
const string delims2
void findFirstOfRange(StringPiece needles, Func func, size_t n)
BENCHMARK_RELATIVE ( FindFirstOf2NeedlesByteSet  ,
 
)

Definition at line 200 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_byteset().

200  {
202 }
const string delims2
size_t qfind_first_byte_of_byteset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:42
void findFirstOfRange(StringPiece needles, Func func, size_t n)
BENCHMARK_RELATIVE ( FindFirstOf2NeedlesBitSet  ,
 
)

Definition at line 204 of file RangeFindBenchmark.cpp.

References folly::BENCHMARK_DRAW_LINE(), findFirstOfRange(), and folly::detail::qfind_first_byte_of_bitset().

204  {
206 }
const string delims2
void findFirstOfRange(StringPiece needles, Func func, size_t n)
size_t qfind_first_byte_of_bitset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:27
BENCHMARK_RELATIVE ( FindFirstOf4NeedlesNoSSE  ,
 
)

Definition at line 216 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_nosse().

216  {
218 }
void findFirstOfRange(StringPiece needles, Func func, size_t n)
size_t qfind_first_byte_of_nosse(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.h:92
const string delims4
BENCHMARK_RELATIVE ( FindFirstOf4NeedlesStd  ,
 
)

Definition at line 220 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_std().

220  {
222 }
size_t qfind_first_byte_of_std(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.h:72
void findFirstOfRange(StringPiece needles, Func func, size_t n)
const string delims4
BENCHMARK_RELATIVE ( FindFirstOf4NeedlesByteSet  ,
 
)

Definition at line 224 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_byteset().

224  {
226 }
size_t qfind_first_byte_of_byteset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:42
void findFirstOfRange(StringPiece needles, Func func, size_t n)
const string delims4
BENCHMARK_RELATIVE ( FindFirstOf4NeedlesBitSet  ,
 
)

Definition at line 228 of file RangeFindBenchmark.cpp.

References folly::BENCHMARK_DRAW_LINE(), findFirstOfRange(), and folly::detail::qfind_first_byte_of_bitset().

228  {
230 }
void findFirstOfRange(StringPiece needles, Func func, size_t n)
size_t qfind_first_byte_of_bitset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:27
const string delims4
BENCHMARK_RELATIVE ( FindFirstOf8NeedlesNoSSE  ,
 
)

Definition at line 240 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_nosse().

240  {
242 }
void findFirstOfRange(StringPiece needles, Func func, size_t n)
const string delims8
size_t qfind_first_byte_of_nosse(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.h:92
BENCHMARK_RELATIVE ( FindFirstOf8NeedlesStd  ,
 
)

Definition at line 244 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_std().

244  {
246 }
size_t qfind_first_byte_of_std(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.h:72
void findFirstOfRange(StringPiece needles, Func func, size_t n)
const string delims8
BENCHMARK_RELATIVE ( FindFirstOf8NeedlesByteSet  ,
 
)

Definition at line 248 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_byteset().

248  {
250 }
size_t qfind_first_byte_of_byteset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:42
void findFirstOfRange(StringPiece needles, Func func, size_t n)
const string delims8
BENCHMARK_RELATIVE ( FindFirstOf8NeedlesBitSet  ,
 
)

Definition at line 252 of file RangeFindBenchmark.cpp.

References folly::BENCHMARK_DRAW_LINE(), findFirstOfRange(), and folly::detail::qfind_first_byte_of_bitset().

252  {
254 }
void findFirstOfRange(StringPiece needles, Func func, size_t n)
const string delims8
size_t qfind_first_byte_of_bitset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:27
BENCHMARK_RELATIVE ( FindFirstOf16NeedlesNoSSE  ,
 
)

Definition at line 264 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_nosse().

264  {
266 }
const string delims16
void findFirstOfRange(StringPiece needles, Func func, size_t n)
size_t qfind_first_byte_of_nosse(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.h:92
BENCHMARK_RELATIVE ( FindFirstOf16NeedlesStd  ,
 
)

Definition at line 268 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_std().

268  {
270 }
const string delims16
size_t qfind_first_byte_of_std(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.h:72
void findFirstOfRange(StringPiece needles, Func func, size_t n)
BENCHMARK_RELATIVE ( FindFirstOf16NeedlesByteSet  ,
 
)

Definition at line 272 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_byteset().

272  {
274 }
const string delims16
size_t qfind_first_byte_of_byteset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:42
void findFirstOfRange(StringPiece needles, Func func, size_t n)
BENCHMARK_RELATIVE ( FindFirstOf16NeedlesBitSet  ,
 
)

Definition at line 276 of file RangeFindBenchmark.cpp.

References folly::BENCHMARK_DRAW_LINE(), findFirstOfRange(), and folly::detail::qfind_first_byte_of_bitset().

276  {
278 }
const string delims16
void findFirstOfRange(StringPiece needles, Func func, size_t n)
size_t qfind_first_byte_of_bitset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:27
BENCHMARK_RELATIVE ( FindFirstOf32NeedlesNoSSE  ,
 
)

Definition at line 288 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_nosse().

288  {
290 }
void findFirstOfRange(StringPiece needles, Func func, size_t n)
size_t qfind_first_byte_of_nosse(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.h:92
const string delims32
BENCHMARK_RELATIVE ( FindFirstOf32NeedlesStd  ,
 
)

Definition at line 292 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_std().

292  {
294 }
size_t qfind_first_byte_of_std(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.h:72
void findFirstOfRange(StringPiece needles, Func func, size_t n)
const string delims32
BENCHMARK_RELATIVE ( FindFirstOf32NeedlesByteSet  ,
 
)

Definition at line 296 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_byteset().

296  {
298 }
size_t qfind_first_byte_of_byteset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:42
void findFirstOfRange(StringPiece needles, Func func, size_t n)
const string delims32
BENCHMARK_RELATIVE ( FindFirstOf32NeedlesBitSet  ,
 
)

Definition at line 300 of file RangeFindBenchmark.cpp.

References folly::BENCHMARK_DRAW_LINE(), findFirstOfRange(), and folly::detail::qfind_first_byte_of_bitset().

300  {
302 }
void findFirstOfRange(StringPiece needles, Func func, size_t n)
size_t qfind_first_byte_of_bitset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:27
const string delims32
BENCHMARK_RELATIVE ( FindFirstOf64NeedlesNoSSE  ,
 
)

Definition at line 314 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_nosse().

314  {
316 }
void findFirstOfRange(StringPiece needles, Func func, size_t n)
const string delims64
size_t qfind_first_byte_of_nosse(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.h:92
BENCHMARK_RELATIVE ( FindFirstOf64NeedlesStd  ,
 
)

Definition at line 318 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_std().

318  {
320 }
size_t qfind_first_byte_of_std(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.h:72
void findFirstOfRange(StringPiece needles, Func func, size_t n)
const string delims64
BENCHMARK_RELATIVE ( FindFirstOf64NeedlesByteSet  ,
 
)

Definition at line 322 of file RangeFindBenchmark.cpp.

References findFirstOfRange(), and folly::detail::qfind_first_byte_of_byteset().

322  {
324 }
size_t qfind_first_byte_of_byteset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:42
void findFirstOfRange(StringPiece needles, Func func, size_t n)
const string delims64
BENCHMARK_RELATIVE ( FindFirstOf64NeedlesBitSet  ,
 
)

Definition at line 326 of file RangeFindBenchmark.cpp.

References folly::BENCHMARK_DRAW_LINE(), findFirstOfRange(), and folly::detail::qfind_first_byte_of_bitset().

326  {
328 }
void findFirstOfRange(StringPiece needles, Func func, size_t n)
const string delims64
size_t qfind_first_byte_of_bitset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:27
BENCHMARK_RELATIVE ( FindFirstOfRandomNoSSE  ,
 
)

Definition at line 345 of file RangeFindBenchmark.cpp.

References findFirstOfRandom(), and folly::detail::qfind_first_byte_of_nosse().

345  {
347 }
size_t qfind_first_byte_of_nosse(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.h:92
void findFirstOfRandom(Func func, size_t iters)
BENCHMARK_RELATIVE ( FindFirstOfRandomStd  ,
 
)

Definition at line 349 of file RangeFindBenchmark.cpp.

References findFirstOfRandom(), and folly::detail::qfind_first_byte_of_std().

349  {
351 }
size_t qfind_first_byte_of_std(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.h:72
void findFirstOfRandom(Func func, size_t iters)
BENCHMARK_RELATIVE ( FindFirstOfRandomByteSet  ,
 
)

Definition at line 353 of file RangeFindBenchmark.cpp.

References findFirstOfRandom(), and folly::detail::qfind_first_byte_of_byteset().

353  {
355 }
size_t qfind_first_byte_of_byteset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:42
void findFirstOfRandom(Func func, size_t iters)
BENCHMARK_RELATIVE ( FindFirstOfRandomBitSet  ,
 
)

Definition at line 357 of file RangeFindBenchmark.cpp.

References folly::BENCHMARK_DRAW_LINE(), findFirstOfRandom(), and folly::detail::qfind_first_byte_of_bitset().

357  {
359 }
size_t qfind_first_byte_of_bitset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:27
void findFirstOfRandom(Func func, size_t iters)
BENCHMARK_RELATIVE ( CountDelimsNoSSE  ,
 
)

Definition at line 367 of file RangeFindBenchmark.cpp.

References countHits(), and folly::detail::qfind_first_byte_of_nosse().

367  {
369 }
void countHits(Func func, size_t n)
size_t qfind_first_byte_of_nosse(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.h:92
BENCHMARK_RELATIVE ( CountDelimsStd  ,
 
)

Definition at line 371 of file RangeFindBenchmark.cpp.

References countHits(), and folly::detail::qfind_first_byte_of_std().

371  {
373 }
size_t qfind_first_byte_of_std(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.h:72
void countHits(Func func, size_t n)
BENCHMARK_RELATIVE ( CountDelimsByteSet  ,
 
)

Definition at line 375 of file RangeFindBenchmark.cpp.

References countHits(), and folly::detail::qfind_first_byte_of_byteset().

375  {
377 }
size_t qfind_first_byte_of_byteset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:42
void countHits(Func func, size_t n)
BENCHMARK_RELATIVE ( CountDelimsBitSet  ,
 
)

Definition at line 379 of file RangeFindBenchmark.cpp.

References folly::BENCHMARK_DRAW_LINE(), countHits(), and folly::detail::qfind_first_byte_of_bitset().

379  {
381 }
void countHits(Func func, size_t n)
size_t qfind_first_byte_of_bitset(const StringPieceLite haystack, const StringPieceLite needles)
Definition: RangeCommon.cpp:27
template<class Func >
void countHits ( Func  func,
size_t  n 
)

Definition at line 139 of file RangeFindBenchmark.cpp.

References c, folly::doNotOptimizeAway(), FOR_EACH_RANGE, i, and folly::Range< const char * >::npos.

Referenced by BENCHMARK(), and BENCHMARK_RELATIVE().

139  {
140  StringPiece needles = "\r\n\1";
141  FOR_EACH_RANGE (i, 0, n) {
142  size_t p, c = 0;
143  for (StringPiece left = file;
144  (p = func(left, needles)) != StringPiece::npos;
145  left.advance(p + 1)) {
146  ++c;
147  }
149  }
150 }
void advance(size_type n)
Definition: Range.h:672
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
char c
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
template<class Func >
void findFirstOfRandom ( Func  func,
size_t  iters 
)

Definition at line 333 of file RangeFindBenchmark.cpp.

References folly::doNotOptimizeAway(), and i.

Referenced by BENCHMARK(), and BENCHMARK_RELATIVE().

333  {
334  for (size_t i = 0; i < iters; ++i) {
335  auto test = i % ffoDelim.size();
336  auto p = func(ffoTestString, ffoDelim[test]);
338  }
339 }
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
template<class Func >
void findFirstOfRange ( StringPiece  needles,
Func  func,
size_t  n 
)

Definition at line 153 of file RangeFindBenchmark.cpp.

References folly::doNotOptimizeAway(), FOR_EACH_RANGE, and i.

Referenced by BENCHMARK(), and BENCHMARK_RELATIVE().

153  {
154  FOR_EACH_RANGE (i, 0, n) {
155  const StringPiece haystack = vstrp[i % kVstrSize];
156  doNotOptimizeAway(func(haystack, needles));
157  char x = haystack[0];
158  doNotOptimizeAway(&x);
159  }
160 }
Definition: InvokeTest.cpp:58
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
int main ( int  argc,
char **  argv 
)

Definition at line 399 of file RangeFindBenchmark.cpp.

References folly::runBenchmarks().

399  {
400  gflags::ParseCommandLineFlags(&argc, &argv, true);
401 
402  for (int len : {1, 8, 10, 16, 32, 64, 128, 256, 10 * 1024, 1024 * 1024}) {
403  initStr(len);
404  initDelims(len);
405  initFile(len);
406  runBenchmarks();
407  }
408  return 0;
409 }
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv

Variable Documentation

const string delims1 = "b"

Definition at line 162 of file RangeFindBenchmark.cpp.

const string delims16 = "0123456789bcdefg"

Definition at line 258 of file RangeFindBenchmark.cpp.

const string delims2 = "bc"

Definition at line 186 of file RangeFindBenchmark.cpp.

const string delims32 = "!bcdefghijklmnopqrstuvwxyz_012345"

Definition at line 282 of file RangeFindBenchmark.cpp.

const string delims4 = "bcde"

Definition at line 210 of file RangeFindBenchmark.cpp.

const string delims64
Initial value:
=
"!bcdefghijklmnopqrstuvwxyz_"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789$"

Definition at line 306 of file RangeFindBenchmark.cpp.

const string delims8 = "0123456b"

Definition at line 234 of file RangeFindBenchmark.cpp.