proxygen
NetworkBenchmark.cpp File Reference
#include <vector>
#include <folly/Benchmark.h>
#include <folly/io/Cursor.h>
#include <folly/io/IOBuf.h>
#include <folly/portability/GFlags.h>

Go to the source code of this file.

Functions

 BENCHMARK (reserveBenchmark, iters)
 
 BENCHMARK (chainBenchmark, iters)
 
unique_ptr< IOBufpoolGetIOBuf ()
 
void poolPutIOBuf (unique_ptr< IOBuf > &&buf)
 
 BENCHMARK (poolBenchmark, iters)
 
void setNumbers (size_t size, size_t num)
 
int main (int argc, char **argv)
 

Variables

size_t buf_size = 0
 
size_t num_bufs = 0
 
vector< unique_ptr< IOBuf > > bufPool
 

Function Documentation

BENCHMARK ( reserveBenchmark  ,
iters   
)

Definition at line 32 of file NetworkBenchmark.cpp.

References folly::IOBuf::append(), buf_size, folly::IOBuf::create(), num_bufs, and folly::IOBuf::reserve().

32  {
33  while (iters--) {
34  unique_ptr<IOBuf> iobuf1(IOBuf::create(buf_size));
35  iobuf1->append(buf_size);
36  for (size_t bufs = num_bufs; bufs > 1; bufs--) {
37  iobuf1->reserve(0, buf_size);
38  iobuf1->append(buf_size);
39  }
40  }
41 }
size_t num_bufs
size_t buf_size
BENCHMARK ( chainBenchmark  ,
iters   
)

Definition at line 43 of file NetworkBenchmark.cpp.

References folly::IOBuf::append(), buf_size, folly::IOBuf::create(), folly::gen::move, num_bufs, and folly::IOBuf::prependChain().

43  {
44  while (iters--) {
45  unique_ptr<IOBuf> iobuf1(IOBuf::create(buf_size));
46  iobuf1->append(buf_size);
47  for (size_t bufs = num_bufs; bufs > 1; bufs--) {
48  unique_ptr<IOBuf> iobufNext(IOBuf::create(buf_size));
49  iobuf1->prependChain(std::move(iobufNext));
50  }
51  }
52 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
size_t num_bufs
size_t buf_size
BENCHMARK ( poolBenchmark  ,
iters   
)

Definition at line 76 of file NetworkBenchmark.cpp.

References folly::gen::move, num_bufs, poolGetIOBuf(), poolPutIOBuf(), and folly::IOBuf::prependChain().

76  {
77  while (iters--) {
78  unique_ptr<IOBuf> head = poolGetIOBuf();
79  for (size_t bufs = num_bufs; bufs > 1; bufs--) {
80  unique_ptr<IOBuf> iobufNext = poolGetIOBuf();
81  head->prependChain(std::move(iobufNext));
82  }
83  // cleanup
84  poolPutIOBuf(std::move(head));
85  }
86 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
unique_ptr< IOBuf > poolGetIOBuf()
void prependChain(std::unique_ptr< IOBuf > &&iobuf)
Definition: IOBuf.cpp:509
void poolPutIOBuf(unique_ptr< IOBuf > &&buf)
size_t num_bufs
int main ( int  argc,
char **  argv 
)

Definition at line 151 of file NetworkBenchmark.cpp.

References folly::runBenchmarks(), and setNumbers().

151  {
152  gflags::ParseCommandLineFlags(&argc, &argv, true);
153 
154  setNumbers(10, 10);
156  setNumbers(100, 10);
158  setNumbers(2048, 10);
160  setNumbers(10000, 10);
162  setNumbers(100000, 10);
164  setNumbers(1000000, 10);
166 
167  setNumbers(10, 20);
169 
170  return 0;
171 }
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv
void setNumbers(size_t size, size_t num)
unique_ptr<IOBuf> poolGetIOBuf ( )
inline

Definition at line 55 of file NetworkBenchmark.cpp.

References folly::IOBuf::append(), buf_size, folly::IOBuf::create(), and folly::gen::move.

Referenced by BENCHMARK().

55  {
56  if (bufPool.size() > 0) {
57  unique_ptr<IOBuf> ret = std::move(bufPool.back());
58  bufPool.pop_back();
59  return ret;
60  } else {
61  unique_ptr<IOBuf> iobuf(IOBuf::create(buf_size));
62  iobuf->append(buf_size);
63  return iobuf;
64  }
65 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
vector< unique_ptr< IOBuf > > bufPool
size_t buf_size
void poolPutIOBuf ( unique_ptr< IOBuf > &&  buf)
inline

Definition at line 67 of file NetworkBenchmark.cpp.

References folly::gen::move, cpp.ast::next(), and folly::IOBuf::pop().

Referenced by BENCHMARK().

67  {
68  unique_ptr<IOBuf> head = std::move(buf);
69  while (head) {
70  unique_ptr<IOBuf> next = head->pop();
71  bufPool.push_back(std::move(head));
72  head = std::move(next);
73  }
74 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< IOBuf > pop()
Definition: IOBuf.h:859
vector< unique_ptr< IOBuf > > bufPool
def next(obj)
Definition: ast.py:58
void setNumbers ( size_t  size,
size_t  num 
)

Definition at line 88 of file NetworkBenchmark.cpp.

References buf_size, num_bufs, and folly::size().

Referenced by main().

88  {
89  buf_size = size;
90  num_bufs = num;
91  bufPool.clear();
92 
93  printf("\nBuffer size: %zu, number of buffers: %zu\n\n", size, num);
94 }
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
vector< unique_ptr< IOBuf > > bufPool
size_t num_bufs
size_t buf_size

Variable Documentation

size_t buf_size = 0

Definition at line 29 of file NetworkBenchmark.cpp.

Referenced by BENCHMARK(), poolGetIOBuf(), and setNumbers().

vector<unique_ptr<IOBuf> > bufPool

Definition at line 54 of file NetworkBenchmark.cpp.

size_t num_bufs = 0

Definition at line 30 of file NetworkBenchmark.cpp.

Referenced by BENCHMARK(), and setNumbers().