ext_test_case#

Various helpers to help develop the package.

Benchmarks#

onnx_extended.ext_test_case.measure_time(stmt: str | Callable, context: Dict[str, Any] | None = None, repeat: int = 10, number: int = 50, warmup: int = 1, div_by_number: bool = True, max_time: float | None = None) Dict[str, float][source]#

Measures a statement and returns the results as a dictionary.

Parameters:
  • stmt – string or callable

  • context – variable to know in a dictionary

  • repeat – average over repeat experiment

  • number – number of executions in one row

  • warmup – number of iteration to do before starting the real measurement

  • div_by_number – divide by the number of executions

  • max_time – execute the statement until the total goes beyond this time (approximatively), repeat is ignored, div_by_number must be set to True

Returns:

dictionary

<<<

from pprint import pprint
from math import cos
from onnx_extended.ext_test_case import measure_time

res = measure_time(lambda: cos(0.5))
pprint(res)

>>>

    {'average': 7.819999882485718e-08,
     'context_size': 64,
     'deviation': 1.6613304155911723e-09,
     'max_exec': 8.200004231184721e-08,
     'min_exec': 7.5999996624887e-08,
     'number': 50,
     'repeat': 10,
     'ttime': 7.819999882485718e-07,
     'warmup_time': 2.0000006770715117e-06}

See Timer.repeat for a better understanding of parameter repeat and number. The function returns a duration corresponding to number times the execution of the main statement.

Changed in version 0.4: Parameter max_time was added.