File tree Expand file tree Collapse file tree 1 file changed +1
-29
lines changed Expand file tree Collapse file tree 1 file changed +1
-29
lines changed Original file line number Diff line number Diff line change 11from __future__ import print_function
22
33import time
4+ from IPython .core .magics .execution import _format_time as format_delta
45
56
67class LineWatcher (object ):
@@ -23,35 +24,6 @@ def stop(self):
2324 assert diff > 0
2425 print ('time: %s' % format_delta (diff ))
2526
26-
27- def format_delta (num , suffix = 's' , threshold = 1000 ):
28- """Format the result of a timing in different units depending on a
29- threshold number of base units.
30-
31- Parameters
32- ----------
33- num : float
34- suffix : str
35- threshold : int
36-
37- Returns
38- -------
39- fmt : str
40- A pretty formatted amount of time
41-
42- Notes
43- -----
44- * Based on http://stackoverflow.com/a/1094933/564538
45- """
46- base_unit = 1000000000
47- num *= base_unit # smallest unit is 1 / 1000000000 of the biggest unit
48- for unit in ['n' , 'u' , 'm' , '' ]:
49- if num < threshold :
50- return '%3.2f %s%s' % (num , unit , suffix )
51- num /= threshold
52- return '%.2f %s' % (num , suffix )
53-
54-
5527timer = LineWatcher ()
5628
5729
You can’t perform that action at this time.
0 commit comments