Hi Andrea 2008/5/25 Andrea Gavana <[EMAIL PROTECTED]>: >> When you bench the Cython code, you'll have to take out the Python >> calls (for checking dtype etc.), otherwise you're comparing apples and >> oranges. After I tweaked it, it ran roughly the same time as >> Francesc's version. But like I mentioned before, the Fortran results >> should trump all, so what is going on here? > > I thought I had removed the Python checks from the Cython code (if you > look at the attached files), but maybe I haven't removed them all... > about Fortran, I have no idea: I have 6 different implementations in > Fortran, and they are all slower than the pure NumPy ones. I don't > know if I can optimiza them further (I have asked to a Fortran > newsgroup too, but no faster solution has arisen). I am not even sure > if the defaults f2py compiler options are already on "maximum > optimization" for Fortran. Does anyone know if this is true? Maybe > Pearu can shed some light on this issue...
Here are the timings on my machine. You were right -- you did remove the type checks in the Cython code. It turns out the bottleneck was the "for i in range" loop. I was under the impression that loop was correctly optimised; I'll have a chat with the Cython developers. If I change it to "for i in xrange" or "for i from 0 <= i < n" the speed improves a lot. I used gfortran 4.2.1, and as you can see below, the Fortran implementation beat all the others. --------------------------------------------------------------------- Number Of Cells: 300000 --------------------------------------------------------------------- | Rank | Method Name | Execution Time | Relative Slowness | --------------------------------------------------------------------- 1 Fortran 5 (James) 0.01854820 1.00000 2 Fortran 6 (James) 0.01882849 1.01511 3 Fortran 1 (Mine) 0.01917751 1.03393 4 Fortran 4 {Michael) 0.01927021 1.03893 5 Fortran 2 (Mine) 0.01937311 1.04447 6 NumPy 4 (Nathan-Vector) 0.02008982 1.08311 7 NumPy 2 (Nathan) 0.02046990 1.10361 8 NumPy 5 (Andrea) 0.02108521 1.13678 9 NumPy 1 (Francesc) 0.02211959 1.19255 10 Cython (Stefan) 0.02235680 1.20533 11 Fortran 3 (Alex) 0.02486629 1.34063 12 NumPy 3 (Peter) 0.05020461 2.70671 --------------------------------------------------------------------- Regards Stéfan _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion