Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using timeit on a cython function

I am trying to time a cython compiled function with timeit using the following syntax:

from offset_back import offset_back

print timeit.timeit(stmt='offset_back(10000,1000,1000)',setup='from main import offset_back',number=1000)

but I keep getting "cannot import name offset_back".

When I print(offset_back(10000,1000,1000))
the function gets called fine, is it possible to use timeit on cython code or do I have to use cProfile?``

like image 920
Padraic Cunningham Avatar asked Feb 25 '26 02:02

Padraic Cunningham


1 Answers

Why are you using different syntax in your setup than you used in your example? Why not

print timeit.timeit(stmt='offset_back(10000,1000,1000)',setup='from offset_back import offset_back',number=1000)
like image 193
user590028 Avatar answered Feb 26 '26 21:02

user590028



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!