proxygen
ReadMostlySharedPtrBenchmark.cpp File Reference
#include <folly/experimental/ReadMostlySharedPtr.h>
#include <iostream>
#include <thread>
#include <folly/Benchmark.h>
#include <folly/Memory.h>
#include <folly/portability/GFlags.h>

Go to the source code of this file.

Typedefs

template<typename T >
using TLMainPtr = folly::ReadMostlyMainPtr< T, folly::TLRefCount >
 
template<typename T >
using TLWeakPtr = folly::ReadMostlyWeakPtr< T, folly::TLRefCount >
 

Functions

template<template< typename > class MainPtr, template< typename > class WeakPtr, size_t threadCount>
void benchmark (size_t n)
 
 BENCHMARK (WeakPtrOneThread, n)
 
 BENCHMARK (WeakPtrFourThreads, n)
 
 BENCHMARK (TLReadMostlyWeakPtrOneThread, n)
 
 BENCHMARK (TLReadMostlyWeakPtrFourThreads, n)
 
int main (int argc, char **argv)
 

Typedef Documentation

template<typename T >
using TLMainPtr = folly::ReadMostlyMainPtr<T, folly::TLRefCount>

Definition at line 54 of file ReadMostlySharedPtrBenchmark.cpp.

template<typename T >
using TLWeakPtr = folly::ReadMostlyWeakPtr<T, folly::TLRefCount>

Definition at line 56 of file ReadMostlySharedPtrBenchmark.cpp.

Function Documentation

template<template< typename > class MainPtr, template< typename > class WeakPtr, size_t threadCount>
void benchmark ( size_t  n)

Definition at line 31 of file ReadMostlySharedPtrBenchmark.cpp.

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

31  {
32  MainPtr<int> mainPtr(std::make_unique<int>(42));
33 
34  std::vector<std::thread> ts;
35 
36  for (size_t t = 0; t < threadCount; ++t) {
37  ts.emplace_back([&]() {
38  WeakPtr<int> weakPtr(mainPtr);
39  // Prevent the compiler from hoisting code out of the loop.
40  auto op = [&]() FOLLY_NOINLINE { weakPtr.lock(); };
41 
42  for (size_t i = 0; i < n; ++i) {
43  op();
44  }
45  });
46  }
47 
48  for (auto& t : ts) {
49  t.join();
50  }
51 }
#define FOLLY_NOINLINE
Definition: CPortability.h:142
BENCHMARK ( WeakPtrOneThread  ,
 
)

Definition at line 58 of file ReadMostlySharedPtrBenchmark.cpp.

58  {
59  benchmark<std::shared_ptr, std::weak_ptr, 1>(n);
60 }
BENCHMARK ( WeakPtrFourThreads  ,
 
)

Definition at line 62 of file ReadMostlySharedPtrBenchmark.cpp.

62  {
63  benchmark<std::shared_ptr, std::weak_ptr, 4>(n);
64 }
BENCHMARK ( TLReadMostlyWeakPtrOneThread  ,
 
)

Definition at line 66 of file ReadMostlySharedPtrBenchmark.cpp.

66  {
67  benchmark<TLMainPtr, TLWeakPtr, 1>(n);
68 }
BENCHMARK ( TLReadMostlyWeakPtrFourThreads  ,
 
)

Definition at line 70 of file ReadMostlySharedPtrBenchmark.cpp.

70  {
71  benchmark<TLMainPtr, TLWeakPtr, 4>(n);
72 }
int main ( int  argc,
char **  argv 
)

Definition at line 74 of file ReadMostlySharedPtrBenchmark.cpp.

References folly::runBenchmarks().

74  {
75  gflags::ParseCommandLineFlags(&argc, &argv, true);
76  gflags::SetCommandLineOptionWithMode(
77  "bm_min_usec", "100000", gflags::SET_FLAG_IF_DEFAULT);
78 
80 
81  return 0;
82 }
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv