IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0.0
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

BenchMetric

struct BenchMetric

Defines a benchmark throughput metric.

Fields​

  • ​code (Int): Op-code of the Metric.
  • ​name (String): Metric's name.
  • ​unit (String): Metric's throughput rate unit (count/second).

Implemented traits​

AnyType, Copyable, Deinitable, ImplicitlyCopyable, Movable, Writable

comptime members​

bytes​

comptime bytes = BenchMetric(Int(1), String("DataMovement"), String("GB/s"))

Metric for measuring data movement in bytes per second.

DEFAULTS​

comptime DEFAULTS = List(BenchMetric.elements, BenchMetric.bytes, BenchMetric.flops, __list_literal__=NoneType(None))

Default set of benchmark metrics.

elements​

comptime elements = BenchMetric(Int(0), String("throughput"), String("GElems/s"))

Metric for measuring throughput in elements per second.

flops​

comptime flops = BenchMetric(Int(2), String("Arithmetic"), String("GFLOPS/s"))

Metric for measuring floating point operations per second.

theoretical_flops​

comptime theoretical_flops = BenchMetric(Int(3), String("TheoreticalArithmetic"), String("GFLOPS/s"))

Metric for measuring theoretical floating point operations per second.

Methods​

__eq__​

def __eq__(self, other: Self) -> Bool

Compares two metrics for equality.

Args:

  • ​other (Self): The metric to compare.

Returns:

Bool: True if the two metrics are equal.

__ne__​

def __ne__(self, other: Self) -> Bool

Compares two metrics for inequality.

Args:

  • ​other (Self): The metric to compare.

Returns:

Bool: True if the two metrics are NOT equal.

write_to​

def write_to(self, mut writer: T)

Formats this BenchMetric to the provided Writer.

Args:

  • ​writer (T): The object to write to.

write_repr_to​

def write_repr_to(self, mut writer: T)

Writes the repr of this BenchMetric to a writer.

Args:

  • ​writer (T): The object to write to.

check_name​

def check_name(self, alt_name: String) -> Bool

Checks whether a string contains the metric's name.

Args:

  • ​alt_name (String): Alternative name of a metric.

Returns:

Bool: True if 'alt_name' is valid alternative of the metric's name.

get_metric_from_list​

static def get_metric_from_list(name: String, metric_list: List[Self]) -> Self

Gets a metric from a given list using only the metric's name.

Args:

  • ​name (String): Metric's name.
  • ​metric_list (List[Self]): List of metrics to search.

Returns:

Self: The selected metric.

Raises:

If the operation fails.