I am using an IPython 6.2.1 integration with Eclipse/PyDev on Ubuntu. Python version is 3.5.2.
I often see people timing a script like
>>>%timeit for _ in range(1000): True
10000 loops, best of 3: 37.8 µs per loop
When I perform the same operation, my output is
>>>%timeit for _ in range(1000): True
20.8 µs ± 353 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
Imho, "best of 3" is the better measure, so I would like to change my output.
I read both, the IPython and the Python timeit documentation. They both don't even mention, that the output could differ from "best of 3". Is this a question of Linux/Eclipse/PyDev implementation or is there a way to change the output of the timeit
module?
P.S.: The same happens in the Eclipse console, when I use timeit
, so IPython is probably irrelevant here.
>>>timeit '"-".join(str(n) for n in range(100))'
11 ns ± 0.0667 ns per loop (mean ± std. dev. of 7 runs, 100000000 loops each)
Unutbu pointed out that you can achieve the desired behaviour from within a program. Running the first script calling timeit.main()
here indeed returns the best of 3. But I would prefer a version that I can run interactively in the Eclipse console.
This syntax std/mean/dev was added to IPython in 5 Oct 2016. See the issue #9984 https://github.com/ipython/ipython/pull/9984 about this improvement. And the implementation is here:
"Added mean + stdv to the %timeit magic - New tests pending - "
https://github.com/ipython/ipython/commit/509d8539c555ede6222d13cf1693388429213853#diff-ee52fbe4422737ccaa3d6d0b15ea5189
but syntax "best of 3" comes from python timeit module in main() function and this is generally the same in python2 and 3.
The display is generated by a
TimeitResult
object (see thetimeit??
code listing). With the -o option I get that object which I can examine:It looks like the information to generate the
best of 3
display is still there, but the formatter is gone. It might be found in an older version.Code is in
IPython/core/magics/execution.py