DEV Community

Discussion on: Timing your Python Code

Collapse
 
rpalo profile image
Ryan Palo

You probably already know about this, but if you have luxury of ipython, you can use the %timeit magic!

In [2]: %timeit [math.sin(x) for x in range(5000)]
1000 loops, best of 3: 719 µs per loop
Collapse
 
cnu profile image
Srinivasan Rangarajan

Yes I know in ipython you can do that. But I wrote this module so that I can import it into my modules/projects and log the time taken for a particular function.

Collapse
 
rpalo profile image
Ryan Palo

Gotcha. Yeah, your way works great for logging purposes.