Show More
@@ -85,10 +85,24 b' class TimeitResult(object):' | |||||
85 | return (math.fsum([(x - mean) ** 2 for x in self.timings]) / len(self.timings)) ** 0.5 |
|
85 | return (math.fsum([(x - mean) ** 2 for x in self.timings]) / len(self.timings)) ** 0.5 | |
86 |
|
86 | |||
87 | def __str__(self): |
|
87 | def __str__(self): | |
88 | return (u"%s loop%s, average of %d: %s +- %s per loop (using standard deviation)" |
|
88 | pm = '+-' | |
89 | % (self.loops,"" if self.loops == 1 else "s", self.repeat, |
|
89 | if hasattr(sys.stdout, 'encoding') and sys.stdout.encoding: | |
90 | _format_time(self.average, self._precision), |
|
90 | try: | |
91 | _format_time(self.stdev, self._precision))) |
|
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 | def _repr_pretty_(self, p , cycle): |
|
107 | def _repr_pretty_(self, p , cycle): | |
94 | unic = self.__str__() |
|
108 | unic = self.__str__() | |
@@ -959,20 +973,18 b' python-profiler package from non-free.""")' | |||||
959 | :: |
|
973 | :: | |
960 |
|
974 | |||
961 | In [1]: %timeit pass |
|
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 | In [2]: u = None |
|
978 | In [2]: u = None | |
965 |
|
979 | |||
966 | In [3]: %timeit u is None |
|
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 | In [4]: %timeit -r 4 u == None |
|
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 | In [5]: import time |
|
985 | In [5]: import time | |
973 |
|
986 | |||
974 | In [6]: %timeit -n1 time.sleep(2) |
|
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 | The times reported by %timeit will be slightly higher than those |
|
990 | The times reported by %timeit will be slightly higher than those |
@@ -598,12 +598,12 b' class TestAstTransform(unittest.TestCase):' | |||||
598 | called.add(x) |
|
598 | called.add(x) | |
599 | ip.push({'f':f}) |
|
599 | ip.push({'f':f}) | |
600 |
|
600 | |||
601 |
with tt.AssertPrints(" |
|
601 | with tt.AssertPrints("std. dev. of"): | |
602 | ip.run_line_magic("timeit", "-n1 f(1)") |
|
602 | ip.run_line_magic("timeit", "-n1 f(1)") | |
603 | self.assertEqual(called, {-1}) |
|
603 | self.assertEqual(called, {-1}) | |
604 | called.clear() |
|
604 | called.clear() | |
605 |
|
605 | |||
606 |
with tt.AssertPrints(" |
|
606 | with tt.AssertPrints("std. dev. of"): | |
607 | ip.run_cell_magic("timeit", "-n1 f(2)", "f(3)") |
|
607 | ip.run_cell_magic("timeit", "-n1 f(2)", "f(3)") | |
608 | self.assertEqual(called, {-2, -3}) |
|
608 | self.assertEqual(called, {-2, -3}) | |
609 |
|
609 | |||
@@ -671,12 +671,12 b' class TestAstTransform2(unittest.TestCase):' | |||||
671 | called.add(x) |
|
671 | called.add(x) | |
672 | ip.push({'f':f}) |
|
672 | ip.push({'f':f}) | |
673 |
|
673 | |||
674 |
with tt.AssertPrints(" |
|
674 | with tt.AssertPrints("std. dev. of"): | |
675 | ip.run_line_magic("timeit", "-n1 f(1)") |
|
675 | ip.run_line_magic("timeit", "-n1 f(1)") | |
676 | self.assertEqual(called, {(1,)}) |
|
676 | self.assertEqual(called, {(1,)}) | |
677 | called.clear() |
|
677 | called.clear() | |
678 |
|
678 | |||
679 |
with tt.AssertPrints(" |
|
679 | with tt.AssertPrints("std. dev. of"): | |
680 | ip.run_cell_magic("timeit", "-n1 f(2)", "f(3)") |
|
680 | ip.run_cell_magic("timeit", "-n1 f(2)", "f(3)") | |
681 | self.assertEqual(called, {(2,), (3,)}) |
|
681 | self.assertEqual(called, {(2,), (3,)}) | |
682 |
|
682 |
General Comments 0
You need to be logged in to leave comments.
Login now