File tree Expand file tree Collapse file tree 2 files changed +10
-12
lines changed Expand file tree Collapse file tree 2 files changed +10
-12
lines changed Original file line number Diff line number Diff line change 11from __future__ import print_function
22
3- import time
3+ try :
4+ from time import monotonic
5+ except ImportError :
6+ from monotonic import monotonic
47
58from IPython .core .magics .execution import _format_time as format_delta
69
@@ -13,26 +16,21 @@ class LineWatcher(object):
1316 -----
1417 * Register the `start` and `stop` methods with the IPython events API.
1518 """
16-
17- def __init__ (self ):
18- self .start_time = 0.0
19+ __slots__ = ['start_time' ]
1920
2021 def start (self ):
21- self .start_time = time . time ()
22+ self .start_time = monotonic ()
2223
2324 def stop (self ):
24- stop_time = time .time ()
25-
26- if self .start_time :
27- diff = stop_time - self .start_time
28- assert diff >= 0
29- print ('time: {}' .format (format_delta (diff )))
25+ delta = monotonic () - self .start_time
26+ print (u'time: {}' .format (format_delta (delta )))
3027
3128
3229timer = LineWatcher ()
3330
3431
3532def load_ipython_extension (ip ):
33+ timer .start ()
3634 ip .events .register ('pre_run_cell' , timer .start )
3735 ip .events .register ('post_run_cell' , timer .stop )
3836
Original file line number Diff line number Diff line change 1717 description = 'Time everything in IPython' ,
1818 long_description = long_description ,
1919 license = 'Apache' ,
20- install_requires = ['ipython' ],
20+ install_requires = ['ipython' , 'monotonic ; python_version < "3.3"' ],
2121 classifiers = [
2222 'Environment :: Console' ,
2323 'Intended Audience :: Developers' ,
You can’t perform that action at this time.
0 commit comments