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)

One example of use:

<<<

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

>>>

    {'average': 4.854027647525072e-05, 'deviation': 5.694955468428983e-06, 'min_exec': 4.622992128133774e-05, 'max_exec': 6.559002213180065e-05, 'repeat': 10, 'number': 50, 'size': 100, 'name': 'simple_dot'}
    {'average': 0.00010063285008072853, 'deviation': 7.787317339920208e-06, 'min_exec': 9.716395288705826e-05, 'max_exec': 0.00012394506484270096, 'repeat': 10, 'number': 50, 'size': 100, 'name': 'c11_dot'}
    {'average': 0.00010111825540661811, 'deviation': 1.8793916091498237e-06, 'min_exec': 9.937607683241367e-05, 'max_exec': 0.00010498985648155212, 'repeat': 10, 'number': 50, 'size': 100, 'name': 'c11_dot16'}
    {'average': 9.787818416953086e-05, 'deviation': 1.7082253226661245e-06, 'min_exec': 9.670504368841648e-05, 'max_exec': 0.00010292790830135345, 'repeat': 10, 'number': 50, 'size': 100, 'name': 'c11_dot16_nofcall'}
    {'average': 0.00010081981308758259, 'deviation': 1.22320509677432e-06, 'min_exec': 9.992602281272411e-05, 'max_exec': 0.00010443385690450668, 'repeat': 10, 'number': 50, 'size': 100, 'name': 'c11_dot16_sse'}
    {'average': 5.495753139257431e-05, 'deviation': 3.0136033698753726e-06, 'min_exec': 5.306699313223362e-05, 'max_exec': 6.380211561918259e-05, 'repeat': 10, 'number': 50, 'size': 1000, 'name': 'simple_dot'}
    {'average': 0.00019960792269557714, 'deviation': 3.347212651855339e-06, 'min_exec': 0.00019753002561628819, 'max_exec': 0.0002095429226756096, 'repeat': 10, 'number': 50, 'size': 1000, 'name': 'c11_dot'}
    {'average': 0.000185950705781579, 'deviation': 1.4963599751379632e-06, 'min_exec': 0.00018468592315912247, 'max_exec': 0.0001902589574456215, 'repeat': 10, 'number': 50, 'size': 1000, 'name': 'c11_dot16'}
    {'average': 0.00020088506862521173, 'deviation': 2.7515294342539325e-06, 'min_exec': 0.0001974340993911028, 'max_exec': 0.00020744581706821918, 'repeat': 10, 'number': 50, 'size': 1000, 'name': 'c11_dot16_nofcall'}
    {'average': 0.00017436218913644553, 'deviation': 1.7355477966663976e-06, 'min_exec': 0.00017310096882283688, 'max_exec': 0.000179206021130085, 'repeat': 10, 'number': 50, 'size': 1000, 'name': 'c11_dot16_sse'}
    [{'average': 4.854027647525072e-05,
      'deviation': 5.694955468428983e-06,
      'max_exec': 6.559002213180065e-05,
      'min_exec': 4.622992128133774e-05,
      'name': 'simple_dot',
      'number': 50,
      'repeat': 10,
      'size': 100},
     {'average': 0.00010063285008072853,
      'deviation': 7.787317339920208e-06,
      'max_exec': 0.00012394506484270096,
      'min_exec': 9.716395288705826e-05,
      'name': 'c11_dot',
      'number': 50,
      'repeat': 10,
      'size': 100},
     {'average': 0.00010111825540661811,
      'deviation': 1.8793916091498237e-06,
      'max_exec': 0.00010498985648155212,
      'min_exec': 9.937607683241367e-05,
      'name': 'c11_dot16',
      'number': 50,
      'repeat': 10,
      'size': 100},
     {'average': 9.787818416953086e-05,
      'deviation': 1.7082253226661245e-06,
      'max_exec': 0.00010292790830135345,
      'min_exec': 9.670504368841648e-05,
      'name': 'c11_dot16_nofcall',
      'number': 50,
      'repeat': 10,
      'size': 100},
     {'average': 0.00010081981308758259,
      'deviation': 1.22320509677432e-06,
      'max_exec': 0.00010443385690450668,
      'min_exec': 9.992602281272411e-05,
      'name': 'c11_dot16_sse',
      'number': 50,
      'repeat': 10,
      'size': 100},
     {'average': 5.495753139257431e-05,
      'deviation': 3.0136033698753726e-06,
      'max_exec': 6.380211561918259e-05,
      'min_exec': 5.306699313223362e-05,
      'name': 'simple_dot',
      'number': 50,
      'repeat': 10,
      'size': 1000},
     {'average': 0.00019960792269557714,
      'deviation': 3.347212651855339e-06,
      'max_exec': 0.0002095429226756096,
      'min_exec': 0.00019753002561628819,
      'name': 'c11_dot',
      'number': 50,
      'repeat': 10,
      'size': 1000},
     {'average': 0.000185950705781579,
      'deviation': 1.4963599751379632e-06,
      'max_exec': 0.0001902589574456215,
      'min_exec': 0.00018468592315912247,
      'name': 'c11_dot16',
      'number': 50,
      'repeat': 10,
      'size': 1000},
     {'average': 0.00020088506862521173,
      'deviation': 2.7515294342539325e-06,
      'max_exec': 0.00020744581706821918,
      'min_exec': 0.0001974340993911028,
      'name': 'c11_dot16_nofcall',
      'number': 50,
      'repeat': 10,
      'size': 1000},
     {'average': 0.00017436218913644553,
      'deviation': 1.7355477966663976e-06,
      'max_exec': 0.000179206021130085,
      'min_exec': 0.00017310096882283688,
      '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)[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': 3.9939535781741146e-06, 'deviation': 6.458652259944675e-07, 'min_exec': 3.7390273064374924e-06, 'max_exec': 5.925074219703674e-06, '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