From 012a2a5ac7ca50b19bd3e972aa4367c41cbe51fc Mon Sep 17 00:00:00 2001 From: Lilian Besson Date: Sun, 25 Oct 2015 16:39:52 +0100 Subject: [PATCH] For timeit magic, no s at "loops" if only one loop Just a grammatical correction: no s at "loops" if there is only one loop. It affects the %timeit magic, its doc, and the message about "an intermediate result being cached". --- IPython/core/magics/execution.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/IPython/core/magics/execution.py b/IPython/core/magics/execution.py index 7a9b1905359..7191cf881f5 100644 --- a/IPython/core/magics/execution.py +++ b/IPython/core/magics/execution.py @@ -79,7 +79,11 @@ def __init__(self, loops, repeat, best, worst, all_runs, compile_time, precision self._precision = precision def _repr_pretty_(self, p , cycle): - unic = u"%d loops, best of %d: %s per loop" % (self.loops, self.repeat, + if self.loops == 1: # No s at "loops" if only one loop + unic = u"%d loop, best of %d: %s per loop" % (self.loops, self.repeat, + _format_time(self.best, self._precision)) + else: + unic = u"%d loops, best of %d: %s per loop" % (self.loops, self.repeat, _format_time(self.best, self._precision)) p.text(u'') @@ -956,7 +960,7 @@ def timeit(self, line='', cell=None): In [5]: import time In [6]: %timeit -n1 time.sleep(2) - 1 loops, best of 3: 2 s per loop + 1 loop, best of 3: 2 s per loop The times reported by %timeit will be slightly higher than those @@ -1055,8 +1059,12 @@ def timeit(self, line='', cell=None): if worst > 4 * best and best > 0 and worst > 1e-6: print("The slowest run took %0.2f times longer than the " "fastest. This could mean that an intermediate result " - "is being cached " % (worst / best)) - print(u"%d loops, best of %d: %s per loop" % (number, repeat, + "is being cached." % (worst / best)) + if number == 1: # No s at "loops" if only one loop + print(u"%d loop, best of %d: %s per loop" % (number, repeat, + _format_time(best, precision))) + else: + print(u"%d loops, best of %d: %s per loop" % (number, repeat, _format_time(best, precision))) if tc > tc_min: print("Compiler time: %.2f s" % tc)