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

Go to the source code of this file.

Functions

 DECLARE_bool (benchmark)
 
template<class T >
void runArithmeticBench (int64_t iters)
 
 BENCHMARK (write_uint8, iters)
 
 BENCHMARK (write_uint16, iters)
 
 BENCHMARK (write_uint32, iters)
 
void runPushBenchmark (int64_t iters, const std::string &str)
 
 BENCHMARK (push_64b, iters)
 
 BENCHMARK (push_1024b, iters)
 
 BENCHMARK (append, iters)
 
void preallocate_postallocate_bench (int64_t iters, size_t size)
 
 BENCHMARK (preallocate_postallocate_1b, iters)
 
 BENCHMARK (preallocate_postallocate_4b, iters)
 
 BENCHMARK (preallocate_postallocate_32b, iters)
 
 BENCHMARK (preallocate_postallocate_256b, iters)
 
int main (int argc, char **argv)
 

Variables

constexpr size_t kBenchmarkSize = 4096
 

Function Documentation

BENCHMARK ( write_uint8  ,
iters   
)

Definition at line 41 of file QueueAppenderBenchmark.cpp.

41  {
42  runArithmeticBench<uint8_t>(iters);
43 }
BENCHMARK ( write_uint16  ,
iters   
)

Definition at line 45 of file QueueAppenderBenchmark.cpp.

45  {
46  runArithmeticBench<uint16_t>(iters);
47 }
BENCHMARK ( write_uint32  ,
iters   
)

Definition at line 49 of file QueueAppenderBenchmark.cpp.

49  {
50  runArithmeticBench<uint32_t>(iters);
51 }
BENCHMARK ( push_64b  ,
iters   
)

Definition at line 65 of file QueueAppenderBenchmark.cpp.

References BENCHMARK_SUSPEND, folly::data(), runPushBenchmark(), and string.

65  {
68  data = std::string(64, 'f');
69  }
70  runPushBenchmark(iters, data);
71 }
void runPushBenchmark(int64_t iters, const std::string &str)
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
const char * string
Definition: Conv.cpp:212
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
BENCHMARK ( push_1024b  ,
iters   
)

Definition at line 73 of file QueueAppenderBenchmark.cpp.

References BENCHMARK_SUSPEND, folly::data(), runPushBenchmark(), and string.

73  {
76  data = std::string(1024, 'b');
77  }
78  runPushBenchmark(iters, data);
79 }
void runPushBenchmark(int64_t iters, const std::string &str)
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
const char * string
Definition: Conv.cpp:212
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
BENCHMARK ( append  ,
iters   
)

Definition at line 81 of file QueueAppenderBenchmark.cpp.

References folly::IOBuf::append(), BENCHMARK_SUSPEND, folly::IOBuf::clone(), folly::IOBuf::create(), folly::doNotOptimizeAway(), i, folly::io::QueueAppender::insert(), kBenchmarkSize, and folly::IOBufQueue::move().

81  {
82  constexpr size_t kNumAppendPerIter = 1024;
83 
84  std::unique_ptr<folly::IOBuf> largeBuffer;
86  largeBuffer = folly::IOBuf::create(1024);
87  largeBuffer->append(1024);
88  }
89 
90  while (iters--) {
91  folly::IOBufQueue queue;
92  QueueAppender appender(&queue, kBenchmarkSize);
93  for (size_t i = 0; i < kNumAppendPerIter; ++i) {
94  appender.insert(largeBuffer->clone());
95  }
97  }
98 }
constexpr size_t kBenchmarkSize
static std::unique_ptr< IOBuf > create(std::size_t capacity)
Definition: IOBuf.cpp:229
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
std::unique_ptr< IOBuf > clone() const
Definition: IOBuf.cpp:527
void append(std::size_t amount)
Definition: IOBuf.h:689
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( preallocate_postallocate_1b  ,
iters   
)

Definition at line 116 of file QueueAppenderBenchmark.cpp.

References preallocate_postallocate_bench().

116  {
118 }
void preallocate_postallocate_bench(int64_t iters, size_t size)
BENCHMARK ( preallocate_postallocate_4b  ,
iters   
)

Definition at line 120 of file QueueAppenderBenchmark.cpp.

References preallocate_postallocate_bench().

120  {
122 }
void preallocate_postallocate_bench(int64_t iters, size_t size)
BENCHMARK ( preallocate_postallocate_32b  ,
iters   
)

Definition at line 124 of file QueueAppenderBenchmark.cpp.

References preallocate_postallocate_bench().

124  {
126 }
void preallocate_postallocate_bench(int64_t iters, size_t size)
BENCHMARK ( preallocate_postallocate_256b  ,
iters   
)

Definition at line 128 of file QueueAppenderBenchmark.cpp.

References preallocate_postallocate_bench().

128  {
129  preallocate_postallocate_bench(iters, 256);
130 }
void preallocate_postallocate_bench(int64_t iters, size_t size)
DECLARE_bool ( benchmark  )
int main ( int  argc,
char **  argv 
)

Definition at line 132 of file QueueAppenderBenchmark.cpp.

References folly::runBenchmarks().

132  {
133  gflags::ParseCommandLineFlags(&argc, &argv, true);
135  return 0;
136 }
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv
void preallocate_postallocate_bench ( int64_t  iters,
size_t  size 
)

Definition at line 100 of file QueueAppenderBenchmark.cpp.

References BENCHMARK_SUSPEND, folly::data(), folly::doNotOptimizeAway(), i, kBenchmarkSize, folly::IOBufQueue::move(), folly::IOBufQueue::postallocate(), folly::IOBufQueue::preallocate(), folly::range(), folly::size(), and string.

Referenced by BENCHMARK().

100  {
103  data = std::string(size, 'f');
104  }
105  while (iters--) {
106  folly::IOBufQueue queue;
107  for (size_t i = 0; i < kBenchmarkSize; ++i) {
108  auto range = queue.preallocate(size, kBenchmarkSize);
109  memcpy(range.first, data.data(), size);
110  queue.postallocate(size);
111  }
113  }
114 }
constexpr size_t kBenchmarkSize
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
std::pair< void *, std::size_t > preallocate(std::size_t min, std::size_t newAllocationSize, std::size_t max=std::numeric_limits< std::size_t >::max())
Definition: IOBufQueue.h:356
Gen range(Value begin, Value end)
Definition: Base.h:467
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
const char * string
Definition: Conv.cpp:212
void postallocate(std::size_t n)
Definition: IOBufQueue.h:380
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
template<class T >
void runArithmeticBench ( int64_t  iters)

Definition at line 30 of file QueueAppenderBenchmark.cpp.

References folly::doNotOptimizeAway(), i, kBenchmarkSize, folly::IOBufQueue::move(), folly::T, and folly::io::QueueAppender::write().

30  {
31  while (iters--) {
32  folly::IOBufQueue queue;
33  QueueAppender appender(&queue, kBenchmarkSize);
34  for (size_t i = 0; i < kBenchmarkSize / sizeof(T); ++i) {
35  appender.write((T)0xFB);
36  }
38  }
39 }
#define T(v)
Definition: http_parser.c:233
constexpr size_t kBenchmarkSize
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void runPushBenchmark ( int64_t  iters,
const std::string str 
)

Definition at line 53 of file QueueAppenderBenchmark.cpp.

References folly::doNotOptimizeAway(), i, kBenchmarkSize, folly::IOBufQueue::move(), and folly::io::detail::Writable< Derived >::push().

Referenced by BENCHMARK().

53  {
54  constexpr size_t kNumPushPerIter = 1024;
55  while (iters--) {
56  folly::IOBufQueue queue;
57  QueueAppender appender(&queue, kBenchmarkSize);
58  for (size_t i = 0; i < kNumPushPerIter; ++i) {
59  appender.push(reinterpret_cast<const uint8_t*>(str.data()), str.size());
60  }
62  }
63 }
constexpr size_t kBenchmarkSize
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258

Variable Documentation

constexpr size_t kBenchmarkSize = 4096