iPython %timeit magic command in normal Python files
Project description
Timeit-magic
iPython %timeit
magic command in normal Python files.
from timeit_magic import timeit
def foo(n):
return sum(list(range(n)))
N = 10000
timeit("foo(10_000)", globals=globals())
timeit("foo(100_000_000)", number=10, repeat=1, globals=globals())
>> 98.8 µs ± 1.94 µs per loop (mean ± std. dev. of 7 runs, 5000 loops each)
2.2 s ± 0 ns per loop (mean ± std. dev. of 1 runs, 10 loops each)
Timeit-magic allows you to time code in a .py
file with the same output and behavior as the %timeit
command in iPython and Jupyter Notebook.
It also provides another function, time_it
, which allows you to time a function by decorating it:
from timeit_magic import time_it
@time_it
def foo(n):
return sum(list(range(n)))
N = 10000
# Both time_it and timeit returns the total runtime in seconds
total_time = foo(N)
print(total_time)
>> 97.6 µs ± 2.27 µs per loop (mean ± std. dev. of 7 runs, 5000 loops each)
3.4683985379997466
Both functions accepts the optional arguments repeat
and number
, which does the same as -r
and -n
in %timeit
.
For more usage information, see the function docstrings and the timeit
documentation.
Installation
Timeit-magic can be installed by using $ pip install timeit-magic
.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for timeit_magic-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 628064da8f444f98f697d4817591a71502c2c93cf3d28b1ba5d34cbfd2bb1515 |
|
MD5 | 15e6436020901db600d0c628078b4681 |
|
BLAKE2b-256 | 4bcd2b3d2e8044dd75b67cdb3da0b4255dfdae473260188edf4ce492e82ea350 |