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()

Returns functions to measure.

source on GitHub

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

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

Parameters
  • dims – 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)

One example of use:

<<<

from cpyquickhelper.numbers import check_speed
res = list(check_speed(dims=[100, 1000]))
import pprint
pprint.pprint(res)

>>>

    {'average': 0.0009937866823747754, 'deviation': 3.153574906261869e-05, 'min_exec': 0.000972019974142313, 'max_exec': 0.0010665289591997862, 'repeat': 10, 'number': 50, 'size': 100, 'name': 'simple_dot'}
    {'average': 0.0009347863029688597, 'deviation': 2.9976744011840868e-05, 'min_exec': 0.0009075499838218093, 'max_exec': 0.0010016700252890587, 'repeat': 10, 'number': 50, 'size': 100, 'name': 'c11_dot'}
    {'average': 0.0009434422943741083, 'deviation': 1.579849749265404e-05, 'min_exec': 0.0009310200111940503, 'max_exec': 0.000982849975116551, 'repeat': 10, 'number': 50, 'size': 100, 'name': 'c11_dot16'}
    {'average': 0.0009353730012662709, 'deviation': 1.656623091803246e-05, 'min_exec': 0.0009214800084009767, 'max_exec': 0.0009751589968800545, 'repeat': 10, 'number': 50, 'size': 100, 'name': 'c11_dot16_nofcall'}
    {'average': 0.0009306411258876324, 'deviation': 1.6595356784599616e-05, 'min_exec': 0.0009120299946516752, 'max_exec': 0.0009671699954196811, 'repeat': 10, 'number': 50, 'size': 100, 'name': 'c11_dot16_sse'}
    {'average': 0.0010930682998150586, 'deviation': 1.6569203482098237e-05, 'min_exec': 0.0010780079755932093, 'max_exec': 0.001128078089095652, 'repeat': 10, 'number': 50, 'size': 1000, 'name': 'simple_dot'}
    {'average': 0.0014275179011747241, 'deviation': 1.7089564820543447e-05, 'min_exec': 0.0014065949944779277, 'max_exec': 0.001460694009438157, 'repeat': 10, 'number': 50, 'size': 1000, 'name': 'c11_dot'}
    {'average': 0.0014885112061165274, 'deviation': 1.5544418987235564e-05, 'min_exec': 0.0014713149284943938, 'max_exec': 0.0015218539629131556, 'repeat': 10, 'number': 50, 'size': 1000, 'name': 'c11_dot16'}
    {'average': 0.0014576534973457455, 'deviation': 1.880569191354587e-05, 'min_exec': 0.0014372050063684583, 'max_exec': 0.00149509496986866, 'repeat': 10, 'number': 50, 'size': 1000, 'name': 'c11_dot16_nofcall'}
    {'average': 0.0013948043226264418, 'deviation': 1.6788679911846584e-05, 'min_exec': 0.001380125992000103, 'max_exec': 0.0014354850864037871, 'repeat': 10, 'number': 50, 'size': 1000, 'name': 'c11_dot16_sse'}
    [{'average': 0.0009937866823747754,
      'deviation': 3.153574906261869e-05,
      'max_exec': 0.0010665289591997862,
      'min_exec': 0.000972019974142313,
      'name': 'simple_dot',
      'number': 50,
      'repeat': 10,
      'size': 100},
     {'average': 0.0009347863029688597,
      'deviation': 2.9976744011840868e-05,
      'max_exec': 0.0010016700252890587,
      'min_exec': 0.0009075499838218093,
      'name': 'c11_dot',
      'number': 50,
      'repeat': 10,
      'size': 100},
     {'average': 0.0009434422943741083,
      'deviation': 1.579849749265404e-05,
      'max_exec': 0.000982849975116551,
      'min_exec': 0.0009310200111940503,
      'name': 'c11_dot16',
      'number': 50,
      'repeat': 10,
      'size': 100},
     {'average': 0.0009353730012662709,
      'deviation': 1.656623091803246e-05,
      'max_exec': 0.0009751589968800545,
      'min_exec': 0.0009214800084009767,
      'name': 'c11_dot16_nofcall',
      'number': 50,
      'repeat': 10,
      'size': 100},
     {'average': 0.0009306411258876324,
      'deviation': 1.6595356784599616e-05,
      'max_exec': 0.0009671699954196811,
      'min_exec': 0.0009120299946516752,
      'name': 'c11_dot16_sse',
      'number': 50,
      'repeat': 10,
      'size': 100},
     {'average': 0.0010930682998150586,
      'deviation': 1.6569203482098237e-05,
      'max_exec': 0.001128078089095652,
      'min_exec': 0.0010780079755932093,
      'name': 'simple_dot',
      'number': 50,
      'repeat': 10,
      'size': 1000},
     {'average': 0.0014275179011747241,
      'deviation': 1.7089564820543447e-05,
      'max_exec': 0.001460694009438157,
      'min_exec': 0.0014065949944779277,
      'name': 'c11_dot',
      'number': 50,
      'repeat': 10,
      'size': 1000},
     {'average': 0.0014885112061165274,
      'deviation': 1.5544418987235564e-05,
      'max_exec': 0.0015218539629131556,
      'min_exec': 0.0014713149284943938,
      'name': 'c11_dot16',
      'number': 50,
      'repeat': 10,
      'size': 1000},
     {'average': 0.0014576534973457455,
      'deviation': 1.880569191354587e-05,
      'max_exec': 0.00149509496986866,
      'min_exec': 0.0014372050063684583,
      'name': 'c11_dot16_nofcall',
      'number': 50,
      'repeat': 10,
      'size': 1000},
     {'average': 0.0013948043226264418,
      'deviation': 1.6788679911846584e-05,
      'max_exec': 0.0014354850864037871,
      'min_exec': 0.001380125992000103,
      'name': 'c11_dot16_sse',
      'number': 50,
      'repeat': 10,
      'size': 1000}]

source on GitHub

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

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': 2.7925707399845123e-05, 'deviation': 1.555240124591854e-06, 'min_exec': 2.689007669687271e-05, 'max_exec': 3.24789434671402e-05, 'repeat': 10, 'number': 50, 'context_size': 232}

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