c4dynamics.utils.tictoc.toc

Contents

c4dynamics.utils.tictoc.toc#

c4dynamics.utils.tictoc.toc(show=True)[source]#

Stops the stopwatch timer and reads the elapsed time.

Measures the elapsed time since the last call to tic() and prints the result in seconds.

Returns:

out (float) – Elapsed time in seconds.

Examples

>>> import c4dynamics as c4d
>>> import numpy as np
>>> N = 10000
>>> tic() 
>>> a = np.ones((1, 3))
>>> for i in range(N - 1):
...     a = np.concatenate((a, np.ones((1, 3))))
>>> t1 = toc() 
>>> c4d.cprint('numpy concat: ' + str(1000 * t1) + ' ms', 'r') 
numpy concat: 31.0 ms
>>> tic() 
>>> a = np.zeros((N, 3))
>>> for i in range(N):
...     a[i, :] = np.ones((1, 3))
>>> t2 = toc() 
>>> c4d.cprint('numpy predefined: ' + str(1000 * t2) + ' ms', 'g') 
numpy predefined: 15.0 ms
>>> tic() 
>>> a = []
>>> for i in range(N):
...     a.append([1, 1, 1])
>>> a = np.array(a)
>>> t3 = toc() 
>>> c4d.cprint('list to numpy: ' + str(1000 * t3) + ' ms', 'y') 
list to numpy: 0.0 ms