Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is it possible to capture standard deviation from %%timeit -o?

I get average time to take running function but cannot get standard deviation.

import random
def average_py(n):
    s = 0
    for i in range(n):
        s += random.random()
    return s / n
n = 10_000_000
result_py = %timeit -o average_py(n)

670 ms ± 2.98 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

print(result_py.average)

0.6704248709886867

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I already checked ipython document.

>Solution :

It is accessible through result_py.stdev.

In [1]: import random
   ...: def average_py(n):
   ...:     s = 0
   ...:     for i in range(n):
   ...:         s += random.random()
   ...:     return s / n
   ...: n = 10_000_000

In [2]: result_py = %timeit -o average_py(n)
1.37 s ± 40.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [3]: result_py.stdev
Out[3]: 0.040515329046983364
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading