Metrics

During development and experimentation with numerical algorithms it is often helpful to collect performance metrics. Every algorithm collects metrics specific to its inner workings. These metrics can, for example, be used to determine good default values for tuning parameters.

nsoptim::Metrics

template<int>
class nsoptim::_metrics_internal::Metrics

Full definition at nsoptim/container/metrics.hpp.

A collection of metrics.

Public Functions

Metrics(const std::string&) noexcept

Construct a named collection of metrics.

constexpr char const *name() const noexcept

Get the name(space) of this Metrics object.

Return

The name(space).

Metrics &CreateSubMetrics(const std::string&) noexcept

Create a sub-collection of metrics and add it to this collection.

Return

Reference to the newly created metrics.

Parameters
  • name: Name of the new sub-collection of metrics.

void AddSubMetrics(const Metrics&) const noexcept

Add a sub-collection of Metrics to the collection.

Parameters
  • metrics: A collection of metrics to be added to this metrics collection.

void AddMetric(const std::string&, const double) const noexcept

Add a floating-point metric to the collection.

Parameters
  • name: Name of the metric.

  • value: Value for the metric.

void AddMetric(const std::string&, const int) const noexcept

Add an integer metric to the collection.

Parameters
  • name: Name of the metric.

  • value: Value for the metric.

void AddMetric(const std::string&, const std::string&) const noexcept

Add a string metric to the collection.

Parameters
  • name: Name of the metric.

  • value: Value for the metric.

void AddDetail(const std::string&, const double) const noexcept

Add a floating-point detail to the collection.

Parameters
  • name: Name of the detailed metric.

  • value: Value for the detailed metric.

void AddDetail(const std::string&, const int) const noexcept

Add an integer detail to the collection.

Parameters
  • name: Name of the detailed metric.

  • value: Value for the detailed metric.

void AddDetail(const std::string&, const std::string&) const noexcept

Add a string detail to the collection.

Parameters
  • name: Name of the detailed metric.

  • value: Value for the detailed metric.

constexpr IteratorProxy<Metric<double>> DoubleMetrics() const noexcept

Iterate over all floating-point metrics and details in this collection.

Return

A proxy providing a forward-iterator over Metric<double> objects.

constexpr IteratorProxy<Metric<int>> IntegerMetrics() const noexcept

Iterate over all integer metrics and details in this collection.

Return

A proxy providing a forward-iterator over Metric<int> objects.

constexpr IteratorProxy<Metric<std::string>> StringMetrics() const noexcept

Iterate over all string metrics and details in this collection.

Return

A proxy providing a forward-iterator over Metric<std::string> objects.

constexpr IteratorProxy<Metrics> SubMetrics() const noexcept

Iterate over all nested metrics in this collection.

Return

A proxy providing a forward-iterator over Metrics objects.

template<typename T>
struct nsoptim::Metric

A named metric object.

Public Functions

Metric(const std::string &_name, const T _value)

Construct a named metric object.

Metric(Metric&&) = default

Default move constructor.

Metric &operator=(Metric&&) = default

Default move assignment.

Metric(const Metric&) = default

Default copy constructor.

Metric &operator=(const Metric&) = default

Default copy assignment.

Public Members

std::string name

Name of the metric.

T value

Value of the metric.

Configuration

Collecting metrics comes with a significant overhead and thus performance hit. The library can be configured to either collect important metrics, detailed metrics, or no metrics at all.

  • default: Collect standard metrics.

  • NSOPTIM_METRICS_DISABLED: Completely disable collection of metrics.

  • NSOPTIM_METRICS_ENABLED: Enable regular collection of metrics.

  • NSOPTIM_METRICS_DETAILED: Collect detailed metrics. Comes with significant overhead and not recommended for production.