module numbers.speed_measure

Short summary

module cpyquickhelper.numbers.speed_measure

Measures speed.

source on GitHub

Functions

function

truncated documentation

_fcts

Returns functions to measure.

check_speed

Prints out some information about speed computation of this laptop. See Measures branching in C++ from python to compare.

measure_time

Measures a statement and returns the results as a dictionary.

Documentation

Measures speed.

source on GitHub

cpyquickhelper.numbers.speed_measure._fcts()[source]

Returns functions to measure.

source on GitHub

cpyquickhelper.numbers.speed_measure.check_speed(dims=[100000], repeat=10, number=50, fLOG=<built-in function print>)[source]

Prints out some information about speed computation of this laptop. See Measures branching in C++ from python to compare.

Parameters
  • n – sets of dimensions to try

  • repeat – average over repeat experiment

  • number – number of execution in one row

  • fLOG – logging function

Returns

iterator on results

numpy is multithreaded. For an accurate comparison, this needs to be disabled. This can be done by setting environment variable MKL_NUM_THREADS=1 or by running:

import mkl
mkl.set_num_threads(1)

source on GitHub

cpyquickhelper.numbers.speed_measure.measure_time(stmt, context, repeat=10, number=50, div_by_number=False)[source]

Measures a statement and returns the results as a dictionary.

Parameters
  • stmt – string

  • context – variable to know in a dictionary

  • repeat – average over repeat experiment

  • number – number of executions in one row

  • div_by_number – divide by the number of executions

Returns

dictionary

<<<

from cpyquickhelper.numbers import measure_time
from math import cos

res = measure_time("cos(x)", context=dict(cos=cos, x=5.))
print(res)

>>>

    {'average': 5.382997915148735e-06, 'deviation': 4.188272895068513e-06, 'min_exec': 3.92599031329155e-06, 'max_exec': 1.7943326383829117e-05, 'repeat': 10, 'number': 50, 'context_size': 240}

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.

source on GitHub