teachcompute.ext_test_case#

measure_time#

teachcompute.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, Any][source][source]#

Measures a statement and returns the results as a dictionary.

Paramètres:
  • 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

Renvoie:

dictionary

<<<

from onnx_extended.ext_test_case import measure_time
from math import cos

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

>>>

    {'average': 1.3860000080967438e-07, 'deviation': 4.820787236341976e-09, 'min_exec': 1.340000017080456e-07, 'max_exec': 1.519999977972475e-07, 'repeat': 10, 'number': 50, 'ttime': 1.3860000080967438e-06, 'context_size': 64, 'warmup_time': 1.4199999895936344e-05}

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.

Modifié dans la version 0.4: Parameter max_time was added.