Skip to content

Commit

Permalink
Merge pull request ipython#8852 from ivan-timokhin/timeit-qo
Browse files Browse the repository at this point in the history
Calculate worst time in timeit unconditionally
  • Loading branch information
minrk committed Oct 2, 2015
2 parents 32ee8c1 + 5bd36f6 commit 06a1221
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions IPython/core/magics/execution.py
Expand Up @@ -1041,10 +1041,12 @@ def timeit(self, line='', cell=None):
number *= 10
all_runs = timer.repeat(repeat, number)
best = min(all_runs) / number

worst = max(all_runs) / number
if worst_tuning:
worst = max(worst, worst_tuning)

if not quiet :
worst = max(all_runs) / number
if worst_tuning:
worst = max(worst, worst_tuning)
# Check best timing is greater than zero to avoid a
# ZeroDivisionError.
# In cases where the slowest timing is lesser than a micosecond
Expand Down
5 changes: 5 additions & 0 deletions IPython/core/tests/test_magic.py
Expand Up @@ -568,6 +568,11 @@ def test_timeit_quiet():
with tt.AssertNotPrints("loops"):
_ip.run_cell("%timeit -n1 -r1 -q 1")

def test_timeit_return_quiet():
with tt.AssertNotPrints("loops"):
res = _ip.run_line_magic('timeit', '-n1 -r1 -q -o 1')
assert (res is not None)

@dec.skipif(sys.version_info[0] >= 3, "no differences with __future__ in py3")
def test_timeit_futures():
"Test %timeit with __future__ environments"
Expand Down

0 comments on commit 06a1221

Please sign in to comment.