##// END OF EJS Templates
Improve timeit message to fix ambuiguity....
Matthias Bussonnier -
Show More
@@ -85,14 +85,20 b' class TimeitResult(object):'
85 85 return (math.fsum([(x - mean) ** 2 for x in self.timings]) / len(self.timings)) ** 0.5
86 86
87 87 def __str__(self):
88 return (u"%s loop%s, average of %d: %s +- %s per loop (using standard deviation)"
89 % (self.loops,"" if self.loops == 1 else "s", self.repeat,
90 _format_time(self.average, self._precision),
91 _format_time(self.stdev, self._precision)))
88 return (
89 u"{mean} ± {std} per loop (mean ± std. dev. of {runs} run{run_plural}, {loops} loop{loop_plural} each)"
90 .format(
91 runs = self.repeat,
92 loops = self.loops,
93 loop_plural = "" if self.loops == 1 else "s",
94 run_plural = "" if self.repeat == 1 else "s",
95 mean = _format_time(self.average, self._precision),
96 std = _format_time(self.stdev, self._precision))
97 )
92 98
93 99 def _repr_pretty_(self, p , cycle):
94 unic = self.__str__()
95 p.text(u'<TimeitResult : '+unic+u'>')
100 unic = self.__str__()
101 p.text(u'<TimeitResult : '+unic+u'>')
96 102
97 103
98 104
@@ -959,20 +965,18 b' python-profiler package from non-free.""")'
959 965 ::
960 966
961 967 In [1]: %timeit pass
962 100000000 loops, average of 7: 5.48 ns +- 0.354 ns per loop (using standard deviation)
968 8.26 ns ± 0.12 ns per loop (mean ± std. dev. of 7 runs, 100000000 loops each)
963 969
964 970 In [2]: u = None
965 971
966 972 In [3]: %timeit u is None
967 10000000 loops, average of 7: 22.7 ns +- 2.33 ns per loop (using standard deviation)
973 29.9 ns ± 0.643 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
968 974
969 975 In [4]: %timeit -r 4 u == None
970 10000000 loops, average of 4: 27.5 ns +- 2.91 ns per loop (using standard deviation)
971 976
972 977 In [5]: import time
973 978
974 979 In [6]: %timeit -n1 time.sleep(2)
975 1 loop, average of 7: 2 s +- 4.71 µs per loop (using standard deviation)
976 980
977 981
978 982 The times reported by %timeit will be slightly higher than those
@@ -598,12 +598,12 b' class TestAstTransform(unittest.TestCase):'
598 598 called.add(x)
599 599 ip.push({'f':f})
600 600
601 with tt.AssertPrints("average of "):
601 with tt.AssertPrints("mean ± std"):
602 602 ip.run_line_magic("timeit", "-n1 f(1)")
603 603 self.assertEqual(called, {-1})
604 604 called.clear()
605 605
606 with tt.AssertPrints("average of "):
606 with tt.AssertPrints("mean ± std"):
607 607 ip.run_cell_magic("timeit", "-n1 f(2)", "f(3)")
608 608 self.assertEqual(called, {-2, -3})
609 609
@@ -671,12 +671,12 b' class TestAstTransform2(unittest.TestCase):'
671 671 called.add(x)
672 672 ip.push({'f':f})
673 673
674 with tt.AssertPrints("average of "):
674 with tt.AssertPrints("mean ± std"):
675 675 ip.run_line_magic("timeit", "-n1 f(1)")
676 676 self.assertEqual(called, {(1,)})
677 677 called.clear()
678 678
679 with tt.AssertPrints("average of "):
679 with tt.AssertPrints("mean ± std"):
680 680 ip.run_cell_magic("timeit", "-n1 f(2)", "f(3)")
681 681 self.assertEqual(called, {(2,), (3,)})
682 682
General Comments 0
You need to be logged in to leave comments. Login now