Ocean
|
The HighPerformanceBenchmark object allows to benchmark algorithms with individual categories. More...
Data Structures | |
class | Category |
This class defines a hierarchical category This class is used to group categories based on their names into a hierarchy. More... | |
class | ScopedCategory |
This class implements a scoped benchmark category. More... | |
Public Types | |
typedef std::vector< double > | MeasurementsSeconds |
Definition of a vector holding measurements in seconds. More... | |
typedef std::unordered_map< std::string, MeasurementsSeconds > | MeasurementMap |
Definition of a map mapping category names to measurements. More... | |
typedef std::vector< Category > | Categories |
Typedef for a vector of categories. More... | |
Public Member Functions | |
bool | start () |
Starts benchmarking. More... | |
bool | stop () |
Stops benchmarking. More... | |
void | reset () |
Rests all benchmark categories and measurements. More... | |
bool | isRunning () const |
Returns whether benchmarking is currently active; False by default. More... | |
MeasurementMap | measurementMap () const |
Returns the map with category names and measurement objects. More... | |
std::vector< std::string > | report (const std::string &referenceCategory=std::string()) const |
Creates a performance report as a readable string. More... | |
bool | reportWithHierarchies (std::vector< std::string > &report, const std::string &referenceCategory=std::string(), const std::string &categoryNameDelimiter="::") const |
Creates a performance report for a hierarchy of categories as a human-readable string. More... | |
size_t | measurements (const std::string &category) |
Returns the number of measurements of a specific category. More... | |
Static Public Member Functions | |
static Categories | createCategoryHierarchy (const MeasurementMap &measurementMap, const std::string &categoryNameDelimiter) |
Creates a hierarchy of categories based on their names from a map of measurements. More... | |
static bool | createTokenMatrixFromCategoryHierarchy (const Categories &categories, const std::string referenceCategory, const std::string &categoryNameDelimiter, const bool valuesAsStrings, std::vector< std::vector< Value >> &tokenMatrix) |
Given a hierarchy of categories with measurements, create a matrix with the performance information The output of this function is a matrix where each cell contains the information that the final report will contain. More... | |
Static Public Member Functions inherited from Ocean::Singleton< HighPerformanceBenchmark > | |
static HighPerformanceBenchmark & | get () |
Returns a reference to the unique object. More... | |
Protected Member Functions | |
void | addMeasurement (const std::string &name, const double measurement) |
Adds a benchmark measurement for a specified category. More... | |
HighPerformanceBenchmark () | |
Default constructor. More... | |
~HighPerformanceBenchmark () | |
Destructs an object. More... | |
Protected Member Functions inherited from Ocean::Singleton< HighPerformanceBenchmark > | |
Singleton ()=default | |
Default constructor. More... | |
Protected Attributes | |
MeasurementMap | measurementMap_ |
The map mapping category names to their measurement objects. More... | |
bool | isRunning_ |
True, if benchmarking is running, false by default. More... | |
Lock | lock_ |
The lock object. More... | |
Friends | |
class | Singleton< HighPerformanceBenchmark > |
The HighPerformanceBenchmark object allows to benchmark algorithms with individual categories.
Benchmarking needs to be started before it can be used.
The class is thread-safe. This class creates flat and/or hierarchical reports. In the case of the former, the categories are sorted by their CPU time. For hierarchical reports, the category names can be expanded using a delimiter, for example Foo::Bar
where Bar
is a sub-category of Foo
. In this report the top-level categories (like Foo
) will be sorted by their total CPU time which is accumulated over all of their sub-categories (like Foo::Bar
).
Usage Example:
void SomeClass::computeSomething(...) { HighPerformanceBenchmark::ScopedCategory scopedBenchmark("AlgorithmName"); function0(); function1(); ... } void SomeClass::function0(...) { HighPerformanceBenchmark::ScopedCategory scopedBenchmark("AlgorithmName::Function0"); ... } void SomeClass::function1(...) { HighPerformanceBenchmark::ScopedCategory scopedBenchmark("AlgorithmName::Function1"); utilityFunction0(); ... } void Utility::utilityFunction0(...) { HighPerformanceBenchmark::ScopedCategory scopedBenchmark("UtilityFunction0"); ... } int main() { HighPerformanceBenchmark::get().start(); while (keepLooping) { SomeClass::computeSomething(); } HighPerformanceBenchmark::get().stop(); // Get the normal or hierarchical performance report const std::vector<std::string> report = HighPerformanceBenchmark::get().report(); const std::vector<std::string> reportWithHierarchies = HighPerformanceBenchmark::get().reportWithHierarchies(); }
which will result in something similar to the following for the normal report:
Name | ... AlgorithmName | ... UtilityFunction0 | ... AlgorithmName::Function0 | ... AlgorithmName::Function1 | ...
and for the hierarchical report the output will be similar to this (sub-categories will be appear indented):
Name | ... AlgorithmName | ... Function0 | ... Function1 | ... UtilityFunction0 | ...
Of course, the actual order of the categories depends on their proportional contribution to the overall measured CPU time
typedef std::vector<Category> Ocean::HighPerformanceBenchmark::Categories |
Typedef for a vector of categories.
typedef std::unordered_map<std::string, MeasurementsSeconds> Ocean::HighPerformanceBenchmark::MeasurementMap |
Definition of a map mapping category names to measurements.
typedef std::vector<double> Ocean::HighPerformanceBenchmark::MeasurementsSeconds |
Definition of a vector holding measurements in seconds.
|
inlineprotected |
Default constructor.
|
inlineprotected |
Destructs an object.
|
protected |
Adds a benchmark measurement for a specified category.
name | The name of the category |
measurement | The benchmark measurement in seconds, with range [0, infinity) |
|
static |
Creates a hierarchy of categories based on their names from a map of measurements.
measurementMap | The map of measurements (category -> measurements) for which a hierarchy of categories will be created |
categoryNameDelimiter | The delimiter that is used to separate levels of categories in a hierarchy |
|
static |
Given a hierarchy of categories with measurements, create a matrix with the performance information The output of this function is a matrix where each cell contains the information that the final report will contain.
This intermediate container makes it easy to print the report with aligned columns.
categories | The hierarchy of categories for which a token matrix will created, must be valid and not empty. |
referenceCategory | The optional reference category for to add relative performance values to the report |
categoryNameDelimiter | The optional delimiter that is used to separate levels of categories in a hierarchy |
valuesAsStrings | True, all cells will be of type string; False, column descriptions and category names will be reported as string and all other values as double or integer. |
tokenMatrix | The resulting token matrix for all categories. |
bool Ocean::HighPerformanceBenchmark::isRunning | ( | ) | const |
Returns whether benchmarking is currently active; False by default.
MeasurementMap Ocean::HighPerformanceBenchmark::measurementMap | ( | ) | const |
Returns the map with category names and measurement objects.
size_t Ocean::HighPerformanceBenchmark::measurements | ( | const std::string & | category | ) |
Returns the number of measurements of a specific category.
category | The category for which the number of measurements will be returned |
std::vector<std::string> Ocean::HighPerformanceBenchmark::report | ( | const std::string & | referenceCategory = std::string() | ) | const |
Creates a performance report as a readable string.
referenceCategory | Optional reference category for to add relative performance values to the report |
bool Ocean::HighPerformanceBenchmark::reportWithHierarchies | ( | std::vector< std::string > & | report, |
const std::string & | referenceCategory = std::string() , |
||
const std::string & | categoryNameDelimiter = "::" |
||
) | const |
Creates a performance report for a hierarchy of categories as a human-readable string.
A hierarchy of categories is created by appending the name of a sub-category to the name of category, using a delimiter between both names, for example "Foo::Bar" is a sub-category of "Foo". This process can be repeated recursively ("Foo::Bar::Baz"). Categories without a delimiter in their name - or which cannot be matched otherwise - will be considered top-level categories ("Foo").
The final report will list either 1) all top-level categories with their subsumed sub-categories (which will be indented) or 2) a specific top-level category. All categories and sub-categories will be sorted by their total CPU-time in descending order.
report | The resulting report as a readable string, one string for each line in the report |
referenceCategory | The optional reference category for to add relative performance values to the report |
categoryNameDelimiter | The optional delimiter that is used to separate levels of categories in a hierarchy |
void Ocean::HighPerformanceBenchmark::reset | ( | ) |
Rests all benchmark categories and measurements.
bool Ocean::HighPerformanceBenchmark::start | ( | ) |
bool Ocean::HighPerformanceBenchmark::stop | ( | ) |
|
friend |
|
protected |
True, if benchmarking is running, false by default.
|
mutableprotected |
The lock object.
|
protected |
The map mapping category names to their measurement objects.