Show More
@@ -85,14 +85,28 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 | pm = '+-' | |
|
89 | if hasattr(sys.stdout, 'encoding') and sys.stdout.encoding: | |
|
90 | try: | |
|
91 | u'\xb1'.encode(sys.stdout.encoding) | |
|
92 | pm = u'\xb1' | |
|
93 | except: | |
|
94 | pass | |
|
95 | return ( | |
|
96 | u"{mean} {pm} {std} per loop (mean {pm} std. dev. of {runs} run{run_plural}, {loops} loop{loop_plural} each)" | |
|
97 | .format( | |
|
98 | pm = pm, | |
|
99 | runs = self.repeat, | |
|
100 | loops = self.loops, | |
|
101 | loop_plural = "" if self.loops == 1 else "s", | |
|
102 | run_plural = "" if self.repeat == 1 else "s", | |
|
103 | mean = _format_time(self.average, self._precision), | |
|
104 | std = _format_time(self.stdev, self._precision)) | |
|
105 | ) | |
|
92 | 106 | |
|
93 | 107 | def _repr_pretty_(self, p , cycle): |
|
94 | unic = self.__str__() | |
|
95 | p.text(u'<TimeitResult : '+unic+u'>') | |
|
108 | unic = self.__str__() | |
|
109 | p.text(u'<TimeitResult : '+unic+u'>') | |
|
96 | 110 | |
|
97 | 111 | |
|
98 | 112 | |
@@ -959,20 +973,18 b' python-profiler package from non-free.""")' | |||
|
959 | 973 | :: |
|
960 | 974 | |
|
961 | 975 | In [1]: %timeit pass |
|
962 | 100000000 loops, average of 7: 5.48 ns +- 0.354 ns per loop (using standard deviation) | |
|
976 | 8.26 ns ± 0.12 ns per loop (mean ± std. dev. of 7 runs, 100000000 loops each) | |
|
963 | 977 | |
|
964 | 978 | In [2]: u = None |
|
965 | 979 | |
|
966 | 980 | In [3]: %timeit u is None |
|
967 | 10000000 loops, average of 7: 22.7 ns +- 2.33 ns per loop (using standard deviation) | |
|
981 | 29.9 ns ± 0.643 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each) | |
|
968 | 982 | |
|
969 | 983 | 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 | 984 | |
|
972 | 985 | In [5]: import time |
|
973 | 986 | |
|
974 | 987 | In [6]: %timeit -n1 time.sleep(2) |
|
975 | 1 loop, average of 7: 2 s +- 4.71 µs per loop (using standard deviation) | |
|
976 | 988 | |
|
977 | 989 | |
|
978 | 990 | 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(" |
|
|
601 | with tt.AssertPrints("std. dev. of"): | |
|
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(" |
|
|
606 | with tt.AssertPrints("std. dev. of"): | |
|
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(" |
|
|
674 | with tt.AssertPrints("std. dev. of"): | |
|
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(" |
|
|
679 | with tt.AssertPrints("std. dev. of"): | |
|
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