CppBenchmark  1.0.4.0
C++ Benchmark Library
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
CppBenchmark::Context Class Reference

Benchmark running context. More...

#include <context.h>

Inheritance diagram for CppBenchmark::Context:
CppBenchmark::Phase CppBenchmark::ContextPC CppBenchmark::ContextThreads

Public Member Functions

 Context ()=delete
 
 Context (const Context &) noexcept=default
 
 Context (Context &&) noexcept=default
 
virtual ~Context () noexcept=default
 
Contextoperator= (const Context &) noexcept=default
 
Contextoperator= (Context &&) noexcept=default
 
int x () const noexcept
 Benchmark first parameter. Valid only if not negative! More...
 
int y () const noexcept
 Benchmark second parameter. Valid only if not negative! More...
 
int z () const noexcept
 Benchmark third parameter. Valid only if not negative! More...
 
PhaseMetricsmetrics () noexcept
 Benchmark mutable metrics. More...
 
bool canceled () const noexcept
 Is benchmark execution canceled? More...
 
void Cancel () noexcept
 Cancel benchmark execution. More...
 
virtual std::string description () const
 Get description of the current benchmark running context. More...
 
const std::string & name () const noexcept override
 Get phase name. More...
 
const PhaseMetricsmetrics () const noexcept override
 Get phase metrics. More...
 
std::shared_ptr< PhaseStartPhase (const std::string &phase) override
 Start a new sub-phase with a given name in a single-thread environment. More...
 
std::shared_ptr< PhaseStartPhaseThreadSafe (const std::string &phase) override
 Start a new sub-phase with a given name in a multi-thread environment. More...
 
void StopPhase () override
 Stop measurement of the current phase. More...
 
std::shared_ptr< PhaseScopeScopePhase (const std::string &phase) override
 Start a new sub-phase with a given name in a single-thread environment and wrap it in a PhaseScope. More...
 
std::shared_ptr< PhaseScopeScopePhaseThreadSafe (const std::string &phase) override
 Start a new sub-phase with a given name in a multi-thread environment and wrap it in a PhaseScope. More...
 
- Public Member Functions inherited from CppBenchmark::Phase
 Phase () noexcept=default
 
 Phase (const Phase &)=default
 
 Phase (Phase &&) noexcept=default
 
virtual ~Phase ()=default
 
Phaseoperator= (const Phase &)=default
 
Phaseoperator= (Phase &&) noexcept=default
 

Protected Member Functions

 Context (int x, int y, int z) noexcept
 Create benchmark running context. More...
 

Protected Attributes

int _x
 Benchmark first parameter. Valid only if not negative! More...
 
int _y
 Benchmark second parameter. Valid only if not negative! More...
 
int _z
 Benchmark third parameter. Valid only if not negative! More...
 
PhaseCore_current
 Current benchmark phase. More...
 
PhaseMetrics_metrics
 Current benchmark metrics. More...
 
std::shared_ptr< std::atomic< bool > > _canceled
 Benchmark canceled flag. More...
 

Friends

class BenchmarkBase
 
class Benchmark
 

Detailed Description

Benchmark running context.

Provides access to the current benchmark context information:

Examples
containers.cpp, and sort.cpp.

Definition at line 26 of file context.h.

Constructor & Destructor Documentation

◆ Context() [1/4]

CppBenchmark::Context::Context ( )
delete

◆ Context() [2/4]

CppBenchmark::Context::Context ( const Context )
defaultnoexcept

◆ Context() [3/4]

CppBenchmark::Context::Context ( Context &&  )
defaultnoexcept

◆ ~Context()

virtual CppBenchmark::Context::~Context ( )
virtualdefaultnoexcept

◆ Context() [4/4]

CppBenchmark::Context::Context ( int  x,
int  y,
int  z 
)
inlineprotectednoexcept

Create benchmark running context.

Parameters
x- Benchmark first parameter
y- Benchmark second parameter
z- Benchmark third parameter

Definition at line 92 of file context.h.

Member Function Documentation

◆ Cancel()

void CppBenchmark::Context::Cancel ( )
inlinenoexcept

Cancel benchmark execution.

Definition at line 58 of file context.h.

◆ canceled()

bool CppBenchmark::Context::canceled ( ) const
inlinenoexcept

Is benchmark execution canceled?

Definition at line 56 of file context.h.

◆ description()

std::string CppBenchmark::Context::description ( ) const
virtual

Get description of the current benchmark running context.

Reimplemented in CppBenchmark::ContextThreads, and CppBenchmark::ContextPC.

Definition at line 13 of file context.cpp.

◆ metrics() [1/2]

const PhaseMetrics& CppBenchmark::Context::metrics ( ) const
inlineoverridevirtualnoexcept

Get phase metrics.

Implements CppBenchmark::Phase.

Definition at line 65 of file context.h.

◆ metrics() [2/2]

PhaseMetrics& CppBenchmark::Context::metrics ( )
inlinenoexcept

Benchmark mutable metrics.

Benchmark mutable metrics can be used to increase operations count with PhaseMetrics.AddOperations() method, register processed items with PhaseMetrics.AddItems() method, register processed bytes with PhaseMetrics.AddBytes() method.

Examples
sort.cpp.

Definition at line 53 of file context.h.

◆ name()

const std::string& CppBenchmark::Context::name ( ) const
inlineoverridevirtualnoexcept

Get phase name.

Implements CppBenchmark::Phase.

Definition at line 64 of file context.h.

◆ operator=() [1/2]

Context& CppBenchmark::Context::operator= ( const Context )
defaultnoexcept

◆ operator=() [2/2]

Context& CppBenchmark::Context::operator= ( Context &&  )
defaultnoexcept

◆ ScopePhase()

std::shared_ptr<PhaseScope> CppBenchmark::Context::ScopePhase ( const std::string &  phase)
inlineoverridevirtual

Start a new sub-phase with a given name in a single-thread environment and wrap it in a PhaseScope.

Please note the method is not thread-safe and should not be called in multi-thread environment!

Parameters
phase- Sub-phase name
Returns
Shared pointer to the required benchmark sub-phase scope wrapper

Implements CppBenchmark::Phase.

Definition at line 69 of file context.h.

◆ ScopePhaseThreadSafe()

std::shared_ptr<PhaseScope> CppBenchmark::Context::ScopePhaseThreadSafe ( const std::string &  phase)
inlineoverridevirtual

Start a new sub-phase with a given name in a multi-thread environment and wrap it in a PhaseScope.

Please note the method is thread-safe and might be called in multi-thread environment!

Parameters
phase- Sub-phase name
Returns
Shared pointer to the required thread-safe benchmark sub-phase scope wrapper

Implements CppBenchmark::Phase.

Definition at line 70 of file context.h.

◆ StartPhase()

std::shared_ptr<Phase> CppBenchmark::Context::StartPhase ( const std::string &  phase)
inlineoverridevirtual

Start a new sub-phase with a given name in a single-thread environment.

This method will create or get existent sub-phase with a given name, start benchmark measurement and return it as a shared pointer. Please note the method is not thread-safe and should not be called in multi-thread environment!

Parameters
phase- Sub-phase name
Returns
Shared pointer to the required benchmark sub-phase

Implements CppBenchmark::Phase.

Definition at line 66 of file context.h.

◆ StartPhaseThreadSafe()

std::shared_ptr<Phase> CppBenchmark::Context::StartPhaseThreadSafe ( const std::string &  phase)
inlineoverridevirtual

Start a new sub-phase with a given name in a multi-thread environment.

This method will create or get existent sub-phase with a given name, start benchmark measurement and return it as a shared pointer. Please note the method is thread-safe and might be called in multi-thread environment!

Parameters
phase- Sub-phase name
Returns
Shared pointer to the thread safe benchmark sub-phase

Implements CppBenchmark::Phase.

Definition at line 67 of file context.h.

◆ StopPhase()

void CppBenchmark::Context::StopPhase ( )
inlineoverridevirtual

Stop measurement of the current phase.

Implements CppBenchmark::Phase.

Definition at line 68 of file context.h.

◆ x()

int CppBenchmark::Context::x ( ) const
inlinenoexcept

Benchmark first parameter. Valid only if not negative!

Examples
sort.cpp.

Definition at line 41 of file context.h.

◆ y()

int CppBenchmark::Context::y ( ) const
inlinenoexcept

Benchmark second parameter. Valid only if not negative!

Definition at line 43 of file context.h.

◆ z()

int CppBenchmark::Context::z ( ) const
inlinenoexcept

Benchmark third parameter. Valid only if not negative!

Definition at line 45 of file context.h.

Friends And Related Function Documentation

◆ Benchmark

friend class Benchmark
friend

Definition at line 29 of file context.h.

◆ BenchmarkBase

friend class BenchmarkBase
friend

Definition at line 28 of file context.h.

Member Data Documentation

◆ _canceled

std::shared_ptr<std::atomic<bool> > CppBenchmark::Context::_canceled
protected

Benchmark canceled flag.

Definition at line 84 of file context.h.

◆ _current

PhaseCore* CppBenchmark::Context::_current
protected

Current benchmark phase.

Definition at line 80 of file context.h.

◆ _metrics

PhaseMetrics* CppBenchmark::Context::_metrics
protected

Current benchmark metrics.

Definition at line 82 of file context.h.

◆ _x

int CppBenchmark::Context::_x
protected

Benchmark first parameter. Valid only if not negative!

Definition at line 74 of file context.h.

◆ _y

int CppBenchmark::Context::_y
protected

Benchmark second parameter. Valid only if not negative!

Definition at line 76 of file context.h.

◆ _z

int CppBenchmark::Context::_z
protected

Benchmark third parameter. Valid only if not negative!

Definition at line 78 of file context.h.


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