#if FOLLY_HAVE_EMMINTRIN_H
#include <emmintrin.h> // __v16qi
#endif
+#include <bitset>
#include <iostream>
namespace folly {
return StringPiece::npos;
}
+size_t qfind_first_byte_of_bitset(const StringPiece haystack,
+ const StringPiece needles) {
+ std::bitset<256> s;
+ for (auto needle : needles) {
+ s[(uint8_t)needle] = true;
+ }
+ for (size_t index = 0; index < haystack.size(); ++index) {
+ if (s[(uint8_t)haystack[index]]) {
+ return index;
+ }
+ }
+ return StringPiece::npos;
+}
+
#if FOLLY_HAVE_EMMINTRIN_H && __GNUC_PREREQ(4, 6)
template <bool HAYSTACK_ALIGNED>
size_t qfind_first_byte_of_byteset(const StringPiece haystack,
const StringPiece needles);
+size_t qfind_first_byte_of_bitset(const StringPiece haystack,
+ const StringPiece needles);
+
size_t qfind_first_byte_of_nosse(const StringPiece haystack,
const StringPiece needles);
}}
findFirstOfRange(delims1, detail::qfind_first_byte_of_byteset, n);
}
+BENCHMARK_RELATIVE(FindFirstOf1NeedlesBitSet, n) {
+ findFirstOfRange(delims1, detail::qfind_first_byte_of_bitset, n);
+}
+
BENCHMARK_DRAW_LINE();
const string delims2 = "bc";
findFirstOfRange(delims2, detail::qfind_first_byte_of_byteset, n);
}
+BENCHMARK_RELATIVE(FindFirstOf2NeedlesBitSet, n) {
+ findFirstOfRange(delims2, detail::qfind_first_byte_of_bitset, n);
+}
+
BENCHMARK_DRAW_LINE();
const string delims4 = "bcde";
findFirstOfRange(delims4, detail::qfind_first_byte_of_byteset, n);
}
+BENCHMARK_RELATIVE(FindFirstOf4NeedlesBitSet, n) {
+ findFirstOfRange(delims4, detail::qfind_first_byte_of_bitset, n);
+}
+
BENCHMARK_DRAW_LINE();
const string delims8 = "0123456b";
findFirstOfRange(delims8, detail::qfind_first_byte_of_byteset, n);
}
+BENCHMARK_RELATIVE(FindFirstOf8NeedlesBitSet, n) {
+ findFirstOfRange(delims8, detail::qfind_first_byte_of_bitset, n);
+}
+
BENCHMARK_DRAW_LINE();
const string delims16 = "0123456789bcdefg";
findFirstOfRange(delims16, detail::qfind_first_byte_of_byteset, n);
}
+BENCHMARK_RELATIVE(FindFirstOf16NeedlesBitSet, n) {
+ findFirstOfRange(delims16, detail::qfind_first_byte_of_bitset, n);
+}
+
BENCHMARK_DRAW_LINE();
const string delims32 = "!bcdefghijklmnopqrstuvwxyz_012345";
findFirstOfRange(delims32, detail::qfind_first_byte_of_byteset, n);
}
+BENCHMARK_RELATIVE(FindFirstOf32NeedlesBitSet, n) {
+ findFirstOfRange(delims32, detail::qfind_first_byte_of_bitset, n);
+}
+
BENCHMARK_DRAW_LINE();
const string delims64 = "!bcdefghijklmnopqrstuvwxyz_"
findFirstOfRange(delims64, detail::qfind_first_byte_of_byteset, n);
}
+BENCHMARK_RELATIVE(FindFirstOf64NeedlesBitSet, n) {
+ findFirstOfRange(delims64, detail::qfind_first_byte_of_bitset, n);
+}
+
BENCHMARK_DRAW_LINE();
template <class Func>
findFirstOfRandom(detail::qfind_first_byte_of_byteset, n);
}
+BENCHMARK_RELATIVE(FindFirstOfRandomBitSet, n) {
+ findFirstOfRandom(detail::qfind_first_byte_of_bitset, n);
+}
+
BENCHMARK_DRAW_LINE();
BENCHMARK(CountDelimsBase, n) {
countHits(detail::qfind_first_byte_of_byteset, n);
}
+BENCHMARK_RELATIVE(CountDelimsBitSet, n) {
+ countHits(detail::qfind_first_byte_of_bitset, n);
+}
+
BENCHMARK_DRAW_LINE();
BENCHMARK(FindFirstOfOffsetRange, n) {