benchmark#

benchmark(repeats=5, scale=1, verbose=False, python=True, numpy=True, parallel=False, return_timers=False)[source]#

Benchmark Python performance

Performs a set of standard operations in both Python and Numpy and times how long they take. Results are returned in terms of millions of operations per second (MOPS). With default settings, this function should take very approximately 0.1 s to run (depending on the machine, of course!).

For Python, these operations are: for loops, list append/indexing, dict set/get, and arithmetic. For Numpy, these operations are: random floats, random ints, addition, and multiplication.

Parameters:
  • repeats (int) – the number of times to repeat each test

  • scale (float) – the scale factor to use for the size of the loops/arrays

  • verbose (bool) – print out the results after each repeat

  • python (bool) – whether to run the Python tests

  • numpy (bool) – whether to run the Numpy tests

  • parallel (bool/int) – whether to run the tests across all cores

  • return_timers (bool) – if True, return the timer objects instead of the “MOPS” results

Returns:

A dict with keys “python” and “numpy” for the number of MOPS for each

Examples:

sc.benchmark() # Returns e.g. {'python': 11.43, 'numpy': 236.595}

numpy_mops = sc.benchmark(python=False)['numpy']
if numpy_mops < 100:
    print('Your computer is slow')
elif numpy_mops > 400:
    print('Your computer is fast')
else:
    print('Your computer is normal')

sc.benchmark(parallel=True) # Use all CPUs
New in version 3.0.0.
New in version 3.1.0: “parallel” argument; increased default scale