Skip to content

Commit

Permalink
Merge pull request ipython#8925 from Naereen/patch-1
Browse files Browse the repository at this point in the history
For timeit magic, no s at "loops" if only one loop
  • Loading branch information
Carreau committed Oct 25, 2015
2 parents 5ee65a1 + 012a2a5 commit acb2c91
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions IPython/core/magics/execution.py
Expand Up @@ -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'<TimeitResult : '+unic+u'>')

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit acb2c91

Please sign in to comment.