File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,10 +11,10 @@ $ pip install ipython-autotime
1111
1212``` python
1313In [1 ]: % load_ext autotime
14- time: 295 µs
14+ time: 264 µs (started: 2020 - 12 - 15 11 : 44 : 36 + 0 1 : 00 )
1515
1616In [2 ]: x = 1
17- time: 519 µs
17+ time: 416 µs (started: 2020 - 12 - 15 11 : 44 : 45 + 0 1 : 00 )
1818
1919In [3 ]: x / 0
2020-------------------------------------------------------------------------- -
@@ -23,7 +23,7 @@ ZeroDivisionError Traceback (most recent call last)
2323---- > 1 x/ 0
2424
2525ZeroDivisionError : division by zero
26- time: 79 .7 ms
26+ time: 88 .7 ms (started: 2020 - 12 - 15 11 : 44 : 53 + 0 1 : 00 )
2727```
2828
2929## Want to turn it off?
Original file line number Diff line number Diff line change 22
33from ._version import version as __version__
44
5+ from time import strftime , localtime
6+
57try :
68 from time import monotonic
79except ImportError :
1012from IPython .core .magics .execution import _format_time as format_delta
1113
1214
15+ def format_timestamp (struct_time ):
16+ timestamp = strftime ('%Y-%m-%d %H:%M:%S %z' , struct_time )
17+ # add colon in %z (for datetime.fromisoformat, stackoverflow.com/q/44836581)
18+ return '{}:{}' .format (timestamp [:- 2 ], timestamp [- 2 :])
19+
20+
1321class LineWatcher (object ):
1422 """Class that implements a basic timer.
1523
1624 Notes
1725 -----
1826 * Register the `start` and `stop` methods with the IPython events API.
1927 """
20- __slots__ = ['start_time' ]
28+ __slots__ = ['start_time' , 'timestamp' ]
2129
2230 def start (self ):
31+ self .timestamp = localtime ()
2332 self .start_time = monotonic ()
2433
2534 def stop (self ):
2635 delta = monotonic () - self .start_time
27- print (u'time: {}' .format (format_delta (delta )))
36+ print (
37+ u'time: {} (started: {})' .format (
38+ format_delta (delta ),
39+ format_timestamp (self .timestamp ),
40+ )
41+ )
2842
2943
3044timer = LineWatcher ()
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ def test_full_cycle():
1010 with tt .AssertPrints ('time: ' ):
1111 ip .run_cell ('%load_ext autotime' )
1212
13- with tt .AssertPrints ('time : ' ):
13+ with tt .AssertPrints (' (started : ' ):
1414 ip .run_cell ('x = 1' )
1515
1616 with tt .AssertNotPrints ('time: ' ):
You can’t perform that action at this time.
0 commit comments