proxygen
folly::BenchmarkSuspender Struct Reference

#include <Benchmark.h>

Public Types

using Clock = std::chrono::high_resolution_clock
 
using TimePoint = Clock::time_point
 
using Duration = Clock::duration
 

Public Member Functions

 BenchmarkSuspender ()
 
 BenchmarkSuspender (const BenchmarkSuspender &)=delete
 
 BenchmarkSuspender (BenchmarkSuspender &&rhs) noexcept
 
BenchmarkSuspenderoperator= (const BenchmarkSuspender &)=delete
 
BenchmarkSuspenderoperator= (BenchmarkSuspender &&rhs)
 
 ~BenchmarkSuspender ()
 
void dismiss ()
 
void rehire ()
 
template<class F >
auto dismissing (F f) -> invoke_result_t< F >
 
 operator bool () const
 

Static Public Attributes

static Duration timeSpent
 

Private Member Functions

void tally ()
 

Private Attributes

TimePoint start
 

Detailed Description

Supporting type for BENCHMARK_SUSPEND defined below.

Definition at line 87 of file Benchmark.h.

Member Typedef Documentation

using folly::BenchmarkSuspender::Clock = std::chrono::high_resolution_clock

Definition at line 88 of file Benchmark.h.

using folly::BenchmarkSuspender::Duration = Clock::duration

Definition at line 90 of file Benchmark.h.

using folly::BenchmarkSuspender::TimePoint = Clock::time_point

Definition at line 89 of file Benchmark.h.

Constructor & Destructor Documentation

folly::BenchmarkSuspender::BenchmarkSuspender ( )
inline

Definition at line 92 of file Benchmark.h.

References now(), and start.

92  {
93  start = Clock::now();
94  }
std::chrono::steady_clock::time_point now()
folly::BenchmarkSuspender::BenchmarkSuspender ( const BenchmarkSuspender )
delete
folly::BenchmarkSuspender::BenchmarkSuspender ( BenchmarkSuspender &&  rhs)
inlinenoexcept

Definition at line 97 of file Benchmark.h.

References folly::detail::rhs, and start.

97  {
98  start = rhs.start;
99  rhs.start = {};
100  }
FOLLY_PUSH_WARNING RHS rhs
Definition: Traits.h:649
folly::BenchmarkSuspender::~BenchmarkSuspender ( )
inline

Definition at line 112 of file Benchmark.h.

References start.

112  {
113  if (start != TimePoint{}) {
114  tally();
115  }
116  }
StatsClock::time_point TimePoint

Member Function Documentation

void folly::BenchmarkSuspender::dismiss ( )
inline
template<class F >
auto folly::BenchmarkSuspender::dismissing ( f) -> invoke_result_t<F>
inline

Definition at line 130 of file Benchmark.h.

References f, and SCOPE_EXIT.

Referenced by BENCHMARK(), BENCHMARK_RELATIVE(), and runContended().

130  {
131  SCOPE_EXIT {
132  rehire();
133  };
134  dismiss();
135  return f();
136  }
auto f
#define SCOPE_EXIT
Definition: ScopeGuard.h:274
folly::BenchmarkSuspender::operator bool ( ) const
inlineexplicit

This is for use inside of if-conditions, used in BENCHMARK macros. If-conditions bypass the explicit on operator bool.

Definition at line 142 of file Benchmark.h.

142  {
143  return false;
144  }
BenchmarkSuspender& folly::BenchmarkSuspender::operator= ( const BenchmarkSuspender )
delete
BenchmarkSuspender& folly::BenchmarkSuspender::operator= ( BenchmarkSuspender &&  rhs)
inline

Definition at line 103 of file Benchmark.h.

References folly::detail::rhs, and start.

103  {
104  if (start != TimePoint{}) {
105  tally();
106  }
107  start = rhs.start;
108  rhs.start = {};
109  return *this;
110  }
FOLLY_PUSH_WARNING RHS rhs
Definition: Traits.h:649
StatsClock::time_point TimePoint
void folly::BenchmarkSuspender::rehire ( )
inline

Definition at line 124 of file Benchmark.h.

References now(), and start.

Referenced by contend(), inlineObserve(), notifyInlineObservers(), notifySubscribers(), observe(), runTest(), runTestTag(), subscribeImpl(), zeroCopyOff(), and zeroCopyOn().

124  {
125  assert(start == TimePoint{});
126  start = Clock::now();
127  }
std::chrono::steady_clock::time_point now()
StatsClock::time_point TimePoint
void folly::BenchmarkSuspender::tally ( )
inlineprivate

Definition at line 152 of file Benchmark.h.

References folly::test::end(), now(), and start.

152  {
153  auto end = Clock::now();
154  timeSpent += end - start;
155  start = end;
156  }
std::chrono::steady_clock::time_point now()
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
static Duration timeSpent
Definition: Benchmark.h:149

Member Data Documentation

TimePoint folly::BenchmarkSuspender::start
private

Definition at line 158 of file Benchmark.h.

std::chrono::high_resolution_clock::duration folly::BenchmarkSuspender::timeSpent
static

Accumulates time spent outside benchmark.

Definition at line 149 of file Benchmark.h.

Referenced by folly::addBenchmark().


The documentation for this struct was generated from the following files: