On Sat, Dec 13, 2008 at 7:36 AM, Joris De Ridder <[email protected]> wrote: > > On 12 Dec 2008, at 1:33 , Joris De Ridder wrote: > >> I implemented the same function using C++ & ctypes, and the latter >> function turns out to be about 100 times faster than the cython one, >> for a 500x500 image, and dx,dy = 5,5. This surprises me, because of >> the simplicity of the function. I checked the C file, and also the >> translation of the maxfilter() function in C is quite simple. The >> bulk of the time is of course spent in the loops, and the only >> bottleneck that I can see is accessing the numpy arrays. Is there >> anything I can do in Cython to speed that up? > > My statement turned out to be wrong: I misread the unit of the > timing. :-/ Cython took 168 ms, ctypes+Cpp took 1.41 s. Prejudiced > about the speed of C++, I misread the latter as 1.41 ms.
:) > So, it turns > out that Cython was actually 10 times faster! I'm still a bit puzzled > about this difference, but it's on the ctypes side I have to look, not > on the cython side. Note that ctypes has a non negligeable cost (because you can easily go through several function calls for each call to the underlying dll, which is costly in python), depending on how you use it. Your cython code can also be sped up by using direct index computing on the data buffer instead of using numpy indexing, but only by 30 % or though, at least on my machine, David _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
