proxygen
IOBufCursorBenchmark.cpp File Reference
#include <folly/io/IOBuf.h>
#include <folly/Benchmark.h>
#include <folly/Format.h>
#include <folly/Range.h>
#include <folly/io/Cursor.h>

Go to the source code of this file.

Functions

 DECLARE_bool (benchmark)
 
template<class CursClass >
void runBenchmark ()
 
 BENCHMARK (rwPrivateCursorBenchmark, iters)
 
 BENCHMARK (rwUnshareCursorBenchmark, iters)
 
 BENCHMARK (cursorBenchmark, iters)
 
 BENCHMARK (skipBenchmark, iters)
 
 BENCHMARK (cloneBenchmark, iters)
 
 BENCHMARK (read, iters)
 
 BENCHMARK (readSlow, iters)
 
bool prefixBaseline (Cursor &c, const std::array< uint8_t, 4 > &expected)
 
bool prefix (Cursor &c, uint32_t expected)
 
 BENCHMARK (prefixBaseline, iters)
 
 BENCHMARK_RELATIVE (prefix, iters)
 
int main (int argc, char **argv)
 

Variables

int benchmark_size = 1000
 
unique_ptr< IOBufiobuf_benchmark
 
unique_ptr< IOBufiobuf_read_benchmark
 

Function Documentation

BENCHMARK ( rwPrivateCursorBenchmark  ,
iters   
)

Definition at line 47 of file IOBufCursorBenchmark.cpp.

47  {
48  while (iters--) {
49  runBenchmark<RWPrivateCursor>();
50  }
51 }
BENCHMARK ( rwUnshareCursorBenchmark  ,
iters   
)

Definition at line 53 of file IOBufCursorBenchmark.cpp.

53  {
54  while (iters--) {
55  runBenchmark<RWUnshareCursor>();
56  }
57 }
BENCHMARK ( cursorBenchmark  ,
iters   
)

Definition at line 59 of file IOBufCursorBenchmark.cpp.

References benchmark_size, c, i, and uint8_t.

59  {
60  while (iters--) {
62  for (int i = 0; i < benchmark_size; i++) {
63  c.read<uint8_t>();
64  }
65  }
66 }
int benchmark_size
unique_ptr< IOBuf > iobuf_read_benchmark
char c
BENCHMARK ( skipBenchmark  ,
iters   
)

Definition at line 68 of file IOBufCursorBenchmark.cpp.

References benchmark_size, c, and i.

68  {
69  while (iters--) {
71  for (int i = 0; i < benchmark_size; i++) {
72  c.peekBytes();
73  c.skip(1);
74  }
75  }
76 }
int benchmark_size
unique_ptr< IOBuf > iobuf_read_benchmark
char c
BENCHMARK ( cloneBenchmark  ,
iters   
)

Definition at line 78 of file IOBufCursorBenchmark.cpp.

References benchmark_size, c, and i.

78  {
79  folly::IOBuf out;
80  while (iters--) {
82  for (int i = 0; i < benchmark_size; ++i) {
83  c.clone(out, 1);
84  }
85  }
86 }
int benchmark_size
unique_ptr< IOBuf > iobuf_read_benchmark
char c
BENCHMARK ( read  ,
iters   
)

Definition at line 88 of file IOBufCursorBenchmark.cpp.

References benchmark_size, c, folly::doNotOptimizeAway(), i, uint8_t, and val.

88  {
89  while (iters--) {
91  for (int i = 0; i < benchmark_size; ++i) {
92  const auto val = c.read<uint8_t>();
94  }
95  }
96 }
int benchmark_size
double val
Definition: String.cpp:273
unique_ptr< IOBuf > iobuf_read_benchmark
char c
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( readSlow  ,
iters   
)

Definition at line 98 of file IOBufCursorBenchmark.cpp.

References benchmark_size, c, folly::doNotOptimizeAway(), i, folly::size(), uint16_t, and val.

98  {
99  while (iters--) {
101  const int size = benchmark_size / 2;
102  for (int i = 0; i < size; ++i) {
103  const auto val = c.read<uint16_t>();
105  }
106  }
107 }
int benchmark_size
double val
Definition: String.cpp:273
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
unique_ptr< IOBuf > iobuf_read_benchmark
char c
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( prefixBaseline  ,
iters   
)

Definition at line 125 of file IOBufCursorBenchmark.cpp.

References benchmark_size, c, folly::IOBuf::CREATE, folly::doNotOptimizeAway(), i, prefix(), and prefixBaseline().

125  {
126  IOBuf buf{IOBuf::CREATE, 10};
127  buf.append(10);
128  constexpr std::array<uint8_t, 4> prefix = {{0x01, 0x02, 0x03, 0x04}};
129  while (iters--) {
130  for (int i = 0; i < benchmark_size; ++i) {
131  Cursor c(&buf);
132  bool result = prefixBaseline(c, prefix);
133  folly::doNotOptimizeAway(result);
134  }
135  }
136 }
int benchmark_size
bool prefixBaseline(Cursor &c, const std::array< uint8_t, 4 > &expected)
bool prefix(Cursor &c, uint32_t expected)
char c
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK_RELATIVE ( prefix  ,
iters   
)

Definition at line 138 of file IOBufCursorBenchmark.cpp.

References benchmark_size, c, folly::IOBuf::CREATE, folly::doNotOptimizeAway(), i, and prefix().

138  {
139  IOBuf buf{IOBuf::CREATE, 10};
140  buf.append(10);
141  while (iters--) {
142  for (int i = 0; i < benchmark_size; ++i) {
143  Cursor c(&buf);
144  bool result = prefix(c, 0x01020304);
145  folly::doNotOptimizeAway(result);
146  }
147  }
148 }
int benchmark_size
bool prefix(Cursor &c, uint32_t expected)
char c
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
DECLARE_bool ( benchmark  )
int main ( int  argc,
char **  argv 
)

============================================================================

folly/io/test/IOBufCursorBenchmark.cpp relative time/iter iters/s

rwPrivateCursorBenchmark 1.01us 985.85K rwUnshareCursorBenchmark 1.01us 986.70K cursorBenchmark 4.77us 209.61K skipBenchmark 4.78us 209.42K cloneBenchmark 26.65us 37.52K read 4.35us 230.07K readSlow 5.45us 183.48K prefixBaseline 6.44us 155.24K

prefix 589.31% 1.09us 914.87K

Definition at line 166 of file IOBufCursorBenchmark.cpp.

References folly::IOBuf::append(), benchmark_size, folly::IOBuf::create(), i, folly::gen::move, folly::IOBuf::prependChain(), and folly::runBenchmarks().

166  {
167  gflags::ParseCommandLineFlags(&argc, &argv, true);
168  iobuf_benchmark = IOBuf::create(benchmark_size);
170 
171  iobuf_read_benchmark = IOBuf::create(1);
172  for (int i = 0; i < benchmark_size; i++) {
173  unique_ptr<IOBuf> iobuf2(IOBuf::create(1));
174  iobuf2->append(1);
175  iobuf_read_benchmark->prependChain(std::move(iobuf2));
176  }
177 
179  return 0;
180 }
int benchmark_size
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv
unique_ptr< IOBuf > iobuf_read_benchmark
unique_ptr< IOBuf > iobuf_benchmark
bool prefix ( Cursor c,
uint32_t  expected 
)

Definition at line 117 of file IOBufCursorBenchmark.cpp.

References folly::io::detail::CursorBase< Derived, BufType >::tryReadLE(), and uint32_t.

Referenced by testing::gmock_generated_actions_test::ACTION_P2(), folly::gen::detail::SplitStringSource< DelimiterType >::apply(), BENCHMARK(), BENCHMARK_RELATIVE(), testing::internal::CodeLocation::CodeLocation(), testing::ContainsRegex(), testing::gmock_matchers_test::EMString(), folly::json::escapeStringImpl(), folly::exception_tracer::getCurrentExceptions(), folly::IPAddressV4::longestCommonPrefix(), folly::IPAddressV6::longestCommonPrefix(), testing::internal::BoundSecondMatcher< Tuple2Matcher, Second >::Impl< T >::MatchAndExplain(), testing::gmock_matchers_test::MATCHER_P(), message_for_terminate_with(), folly::gen::StreamSplitter< Callback >::operator()(), folly::operator<(), ReadStats::parseMessage(), testing::gmock_generated_actions_test::SubstractAction::Perform(), folly::SocketAddress::prefixMatch(), testing::internal::PrintOnOneLine(), testing::gtest_printers_test::PrintPointer(), TEST(), testing::gmock_matchers_test::TEST_F(), folly::io::test::TEST_P(), testing::gmock_matchers_test::FloatingPointNearTest< RawType >::TestNearMatches(), folly::toSubprocessSpawnErrorMessage(), folly::hash::SpookyHashV1::Update(), folly::hash::SpookyHashV2::Update(), and vprintfCheck().

117  {
118  uint32_t actual;
119  if (!c.tryReadLE(actual)) {
120  return false;
121  }
122  return actual == expected;
123 }
bool prefixBaseline ( Cursor c,
const std::array< uint8_t, 4 > &  expected 
)

Definition at line 109 of file IOBufCursorBenchmark.cpp.

References folly::io::detail::CursorBase< Derived, BufType >::pullAtMost().

Referenced by BENCHMARK().

109  {
110  std::array<uint8_t, 4> actual;
111  if (c.pullAtMost(actual.data(), actual.size()) != actual.size()) {
112  return false;
113  }
114  return memcmp(actual.data(), expected.data(), actual.size()) == 0;
115 }
size_t pullAtMost(void *buf, size_t len)
Definition: Cursor.h:407
template<class CursClass >
void runBenchmark ( )

Definition at line 39 of file IOBufCursorBenchmark.cpp.

References benchmark_size, c, i, and uint8_t.

39  {
40  CursClass c(iobuf_benchmark.get());
41 
42  for (int i = 0; i < benchmark_size; i++) {
43  c.write((uint8_t)0);
44  }
45 }
int benchmark_size
char c
unique_ptr< IOBuf > iobuf_benchmark

Variable Documentation

int benchmark_size = 1000

Definition at line 33 of file IOBufCursorBenchmark.cpp.

Referenced by BENCHMARK(), BENCHMARK_RELATIVE(), main(), and runBenchmark().

unique_ptr<IOBuf> iobuf_benchmark

Definition at line 34 of file IOBufCursorBenchmark.cpp.

unique_ptr<IOBuf> iobuf_read_benchmark

Definition at line 36 of file IOBufCursorBenchmark.cpp.