22 Feb 16:15
Newbie Questions about speeding up some Numpy calculations
Hanno Klemm <klemm <at> phys.ethz.ch>
2012-02-22 15:15:29 GMT
2012-02-22 15:15:29 GMT
Hi All, I am pretty new to Cython, so please bare with me. I am at the moment trying to speed up some code that I use a lot in calculations, so thought this might be a good idea to learn how to use Cython when I have already some working Numpy code. After searching the tutorials I came up with the attached solution, however compared with the original Numpy code this is getting slightly slower rather than faster, so obviously I am doing something very wrong. Could somebody please give me some pointers where I can find examples that are closer to what I am trying to speed up than what I can find in the tutorials? Attached are the original numpy code, as well as the Cython code I have tried to develop. If I run this on my machine, I get: Python 2.7.2 |EPD 7.2-2 (32-bit)| (default, Sep 7 2011, 09:16:50) Type "copyright", "credits" or "license" for more information. IPython 0.12 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: import be In [2]: timeit be.referencecase(samples=250000) 1 loops, best of 3: 2.12 s per loop In [3]: import be1 In [4]: timeit be1.referencecase(samples=250000) 1 loops, best of 3: 1.82 s per loop
Many thanks, Hanno
RSS Feed