proxygen
IOBufBenchmark.cpp File Reference
#include <folly/Benchmark.h>
#include <folly/io/IOBuf.h>

Go to the source code of this file.

Functions

 BENCHMARK (cloneOneBenchmark, iters)
 
 BENCHMARK (cloneOneIntoBenchmark, iters)
 
 BENCHMARK (cloneBenchmark, iters)
 
 BENCHMARK (cloneIntoBenchmark, iters)
 
 BENCHMARK (moveBenchmark, iters)
 
 BENCHMARK (copyBenchmark, iters)
 
 BENCHMARK (cloneCoalescedBaseline, iters)
 
 BENCHMARK_RELATIVE (cloneCoalescedBenchmark, iters)
 
int main (int argc, char **argv)
 

Function Documentation

BENCHMARK ( cloneOneBenchmark  ,
iters   
)

Definition at line 22 of file IOBufBenchmark.cpp.

References folly::IOBuf::cloneOne(), folly::copy(), CREATE, and folly::doNotOptimizeAway().

22  {
23  IOBuf buf(IOBuf::CREATE, 10);
24  while (iters--) {
25  auto copy = buf.cloneOne();
26  folly::doNotOptimizeAway(copy->capacity());
27  }
28 }
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
Definition: Utility.h:72
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( cloneOneIntoBenchmark  ,
iters   
)

Definition at line 30 of file IOBufBenchmark.cpp.

References folly::IOBuf::capacity(), folly::IOBuf::cloneOneInto(), folly::copy(), CREATE, and folly::doNotOptimizeAway().

30  {
31  IOBuf buf(IOBuf::CREATE, 10);
32  IOBuf copy;
33  while (iters--) {
34  buf.cloneOneInto(copy);
36  }
37 }
std::size_t capacity() const
Definition: IOBuf.h:593
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
Definition: Utility.h:72
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( cloneBenchmark  ,
iters   
)

Definition at line 39 of file IOBufBenchmark.cpp.

References folly::IOBuf::clone(), folly::copy(), CREATE, and folly::doNotOptimizeAway().

39  {
40  IOBuf buf(IOBuf::CREATE, 10);
41  while (iters--) {
42  auto copy = buf.clone();
43  folly::doNotOptimizeAway(copy->capacity());
44  }
45 }
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
Definition: Utility.h:72
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( cloneIntoBenchmark  ,
iters   
)

Definition at line 47 of file IOBufBenchmark.cpp.

References folly::IOBuf::capacity(), folly::IOBuf::cloneInto(), folly::copy(), CREATE, and folly::doNotOptimizeAway().

47  {
48  IOBuf buf(IOBuf::CREATE, 10);
49  IOBuf copy;
50  while (iters--) {
51  buf.cloneInto(copy);
53  }
54 }
std::size_t capacity() const
Definition: IOBuf.h:593
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
Definition: Utility.h:72
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( moveBenchmark  ,
iters   
)

Definition at line 56 of file IOBufBenchmark.cpp.

References CREATE, folly::doNotOptimizeAway(), and folly::gen::move.

56  {
57  IOBuf buf(IOBuf::CREATE, 10);
58  while (iters--) {
59  auto tmp = std::move(buf);
60  folly::doNotOptimizeAway(tmp.capacity());
61  buf = std::move(tmp);
62  }
63 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( copyBenchmark  ,
iters   
)

Definition at line 65 of file IOBufBenchmark.cpp.

References folly::copy(), CREATE, and folly::doNotOptimizeAway().

65  {
66  IOBuf buf(IOBuf::CREATE, 10);
67  while (iters--) {
68  auto copy = buf;
69  folly::doNotOptimizeAway(copy.capacity());
70  }
71 }
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
Definition: Utility.h:72
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( cloneCoalescedBaseline  ,
iters   
)

Definition at line 73 of file IOBufBenchmark.cpp.

References folly::IOBuf::cloneAsValue(), folly::IOBuf::coalesce(), and folly::doNotOptimizeAway().

73  {
74  std::unique_ptr<IOBuf> buf = IOBuf::createChain(100, 10);
75  while (iters--) {
76  auto clone = buf->cloneAsValue();
77  clone.coalesce();
78  folly::doNotOptimizeAway(clone.capacity());
79  }
80 }
ByteRange coalesce()
Definition: IOBuf.h:1095
IOBuf cloneAsValue() const
Definition: IOBuf.cpp:546
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK_RELATIVE ( cloneCoalescedBenchmark  ,
iters   
)

Definition at line 82 of file IOBufBenchmark.cpp.

References folly::IOBuf::cloneCoalescedAsValue(), folly::copy(), and folly::doNotOptimizeAway().

82  {
83  std::unique_ptr<IOBuf> buf = IOBuf::createChain(100, 10);
84  while (iters--) {
85  auto copy = buf->cloneCoalescedAsValue();
86  folly::doNotOptimizeAway(copy.capacity());
87  }
88 }
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
Definition: Utility.h:72
IOBuf cloneCoalescedAsValue() const
Definition: IOBuf.cpp:570
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
int main ( int  argc,
char **  argv 
)

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

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

cloneOneBenchmark 49.03ns 20.39M cloneOneIntoBenchmark 26.36ns 37.93M cloneBenchmark 49.43ns 20.23M cloneIntoBenchmark 30.03ns 33.30M moveBenchmark 15.35ns 65.14M copyBenchmark 33.63ns 29.73M cloneCoalescedBaseline 344.33ns 2.90M

cloneCoalescedBenchmark 605.62% 56.86ns 17.59M

Definition at line 105 of file IOBufBenchmark.cpp.

References folly::runBenchmarks().

105  {
106  gflags::ParseCommandLineFlags(&argc, &argv, true);
108  return 0;
109 }
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv