proxygen
ThreadLocalBenchmark.cpp File Reference
#include <folly/ThreadLocal.h>
#include <sys/types.h>
#include <array>
#include <atomic>
#include <condition_variable>
#include <map>
#include <mutex>
#include <set>
#include <thread>
#include <boost/thread/tss.hpp>
#include <glog/logging.h>
#include <folly/Benchmark.h>
#include <folly/experimental/io/FsUtil.h>
#include <folly/portability/GFlags.h>

Go to the source code of this file.

Classes

class  PThreadGetSpecific< T >
 
struct  foo
 

Macros

#define REG(var)
 

Functions

 DEFINE_int32 (numThreads, 8,"Number simultaneous threads for benchmarks.")
 
 BENCHMARK (FB_CONCATENATE(BM_mt_, tlp), iters)
 
 BENCHMARK (FB_CONCATENATE(BM_mt_, pthread_get_specific), iters)
 
 BENCHMARK (FB_CONCATENATE(BM_mt_, boost_tsp), iters)
 
 BENCHMARK_DRAW_LINE ()
 
template<typename TL >
void run_multi (uint32_t iters)
 
 BENCHMARK (BM_mt_tlp_multi, iters)
 
 BENCHMARK (BM_mt_pthread_get_specific_multi, iters)
 
 BENCHMARK (BM_mt_boost_tsp_multi, iters)
 
int main (int argc, char **argv)
 

Variables

ThreadLocalPtr< int > tlp
 
PThreadGetSpecific< int > pthread_get_specific
 
boost::thread_specific_ptr< int > boost_tsp
 

Macro Definition Documentation

#define REG (   var)
Value:
BENCHMARK(FB_CONCATENATE(BM_mt_, var), iters) { \
const int itersPerThread = iters / FLAGS_numThreads; \
std::vector<std::thread> threads; \
for (int i = 0; i < FLAGS_numThreads; ++i) { \
threads.push_back(std::thread([&]() { \
var.reset(new int(0)); \
for (int j = 0; j < itersPerThread; ++j) { \
++(*var.get()); \
} \
})); \
} \
for (auto& t : threads) { \
t.join(); \
} \
}
BENCHMARK(FB_CONCATENATE(BM_mt_, tlp), iters)
std::vector< std::thread::id > threads
#define FB_CONCATENATE(s1, s2)
Definition: Preprocessor.h:88
const
Definition: upload.py:398

Definition at line 64 of file ThreadLocalBenchmark.cpp.

Function Documentation

BENCHMARK ( FB_CONCATENATE(BM_mt_,tlp ,
iters   
)

Definition at line 82 of file ThreadLocalBenchmark.cpp.

BENCHMARK ( FB_CONCATENATE(BM_mt_,pthread_get_specific ,
iters   
)

Definition at line 84 of file ThreadLocalBenchmark.cpp.

BENCHMARK ( FB_CONCATENATE(BM_mt_,boost_tsp ,
iters   
)

Definition at line 86 of file ThreadLocalBenchmark.cpp.

89 {
BENCHMARK ( BM_mt_tlp_multi  ,
iters   
)

Definition at line 115 of file ThreadLocalBenchmark.cpp.

115  {
116  run_multi<ThreadLocalPtr<foo>>(iters);
117 }
BENCHMARK ( BM_mt_pthread_get_specific_multi  ,
iters   
)

Definition at line 118 of file ThreadLocalBenchmark.cpp.

118  {
119  run_multi<PThreadGetSpecific<foo>>(iters);
120 }
BENCHMARK ( BM_mt_boost_tsp_multi  ,
iters   
)

Definition at line 121 of file ThreadLocalBenchmark.cpp.

References folly::BENCHMARK_DRAW_LINE().

121  {
122  run_multi<boost::thread_specific_ptr<foo>>(iters);
123 }
BENCHMARK_DRAW_LINE ( )
DEFINE_int32 ( numThreads  ,
,
"Number simultaneous threads for benchmarks."   
)
int main ( int  argc,
char **  argv 
)

Definition at line 126 of file ThreadLocalBenchmark.cpp.

References folly::runBenchmarks().

126  {
127  gflags::ParseCommandLineFlags(&argc, &argv, true);
128  gflags::SetCommandLineOptionWithMode(
129  "bm_max_iters", "100000000", gflags::SET_FLAG_IF_DEFAULT);
131  return 0;
132 }
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv
template<typename TL >
void run_multi ( uint32_t  iters)

Definition at line 95 of file ThreadLocalBenchmark.cpp.

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

95  {
96  const int itersPerThread = iters / FLAGS_numThreads;
97  std::vector<std::thread> threads;
98  TL var;
99  for (int i = 0; i < FLAGS_numThreads; ++i) {
100  threads.push_back(std::thread([&]() {
101  var.reset(new foo);
102  for (int j = 0; j < itersPerThread; ++j) {
103  ++var.get()->a;
104  var.get()->b += var.get()->a;
105  --var.get()->a;
106  var.get()->b += var.get()->a;
107  }
108  }));
109  }
110  for (auto& t : threads) {
111  t.join();
112  }
113 }
std::vector< std::thread::id > threads

Variable Documentation

boost::thread_specific_ptr<int> boost_tsp

Definition at line 85 of file ThreadLocalBenchmark.cpp.

PThreadGetSpecific<int> pthread_get_specific

Definition at line 83 of file ThreadLocalBenchmark.cpp.

ThreadLocalPtr<int> tlp

Definition at line 81 of file ThreadLocalBenchmark.cpp.