proxygen
CallOnceBenchmark.cpp File Reference
#include <folly/synchronization/CallOnce.h>
#include <deque>
#include <mutex>
#include <thread>
#include <folly/Benchmark.h>
#include <glog/logging.h>

Go to the source code of this file.

Functions

 DEFINE_int32 (threads, 16,"benchmark concurrency")
 
template<typename CallOnceFunc >
void bm_impl (CallOnceFunc &&fn, size_t iters)
 
 BENCHMARK (StdCallOnceBench, iters)
 
 BENCHMARK (FollyCallOnceBench, iters)
 
int main (int argc, char **argv)
 

Function Documentation

BENCHMARK ( StdCallOnceBench  ,
iters   
)

Definition at line 44 of file CallOnceBenchmark.cpp.

References bm_impl(), folly::call_once(), and flag.

44  {
46  int out = 0;
47  bm_impl([&] { std::call_once(flag, [&] { ++out; }); }, iters);
48  CHECK_EQ(1, out);
49 }
void bm_impl(CallOnceFunc &&fn, size_t iters)
static once_flag flag
Definition: Random.cpp:75
FOLLY_ALWAYS_INLINE void call_once(basic_once_flag< Mutex, Atom > &flag, F &&f, Args &&...args)
Definition: CallOnce.h:56
basic_once_flag< TimedMutex > once_flag
Definition: CallOnce.h:23
BENCHMARK ( FollyCallOnceBench  ,
iters   
)

Definition at line 51 of file CallOnceBenchmark.cpp.

References bm_impl(), folly::call_once(), and flag.

51  {
53  int out = 0;
54  bm_impl([&] { folly::call_once(flag, [&] { ++out; }); }, iters);
55  CHECK_EQ(1, out);
56 }
void bm_impl(CallOnceFunc &&fn, size_t iters)
static once_flag flag
Definition: Random.cpp:75
FOLLY_ALWAYS_INLINE void call_once(basic_once_flag< Mutex, Atom > &flag, F &&f, Args &&...args)
Definition: CallOnce.h:56
template<typename CallOnceFunc >
void bm_impl ( CallOnceFunc &&  fn,
size_t  iters 
)

Definition at line 30 of file CallOnceBenchmark.cpp.

References i, folly::pushmi::detail::t, and threads.

Referenced by BENCHMARK().

30  {
31  std::deque<std::thread> threads;
32  for (size_t i = 0u; i < size_t(FLAGS_threads); ++i) {
33  threads.emplace_back([&fn, iters] {
34  for (size_t j = 0u; j < iters; ++j) {
35  fn();
36  }
37  });
38  }
39  for (std::thread& t : threads) {
40  t.join();
41  }
42 }
std::vector< std::thread::id > threads
DEFINE_int32 ( threads  ,
16  ,
"benchmark concurrency"   
)
int main ( int  argc,
char **  argv 
)

Definition at line 68 of file CallOnceBenchmark.cpp.

References folly::runBenchmarks().

68  {
69  gflags::ParseCommandLineFlags(&argc, &argv, true);
71  return 0;
72 }
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv