diff options
author | Rémi Flamary <remi.flamary@gmail.com> | 2017-01-05 13:48:09 +0100 |
---|---|---|
committer | Rémi Flamary <remi.flamary@gmail.com> | 2017-01-05 13:48:09 +0100 |
commit | e1cd68bd8e8a2c7334595d1b4ea0bc9dccfd3013 (patch) | |
tree | 0de1eae6814e76616a5f995a28fc6fa1eb4bfaca /ot/utils.py | |
parent | b90ea88f8f0cf32aef102277588f80042c6cfcaa (diff) |
add tic() and toc() functions for easy coarse timing
Diffstat (limited to 'ot/utils.py')
-rw-r--r-- | ot/utils.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/ot/utils.py b/ot/utils.py index d3df8fa..2f68775 100644 --- a/ot/utils.py +++ b/ot/utils.py @@ -6,6 +6,26 @@ import numpy as np from scipy.spatial.distance import cdist +import time +__time_tic_toc=time.time() + +def tic(): + """ Python implementation of Matlab tic() function """ + global __time_tic_toc + __time_tic_toc=time.time() + +def toc(message='Elapsed time : {} s'): + """ Python implementation of Matlab toc() function """ + t=time.time() + print(message.format(t-__time_tic_toc)) + return t-__time_tic_toc + +def toq(): + """ Python implementation of Julia toc() function """ + t=time.time() + return t-__time_tic_toc + + def kernel(x1,x2,method='gaussian',sigma=1,**kwargs): """Compute kernel matrix""" if method.lower() in ['gaussian','gauss','rbf']: |