[SciPy-user] Why is weave.inline()/blitz++ code 3 times slower than innerproduct()?

Robert Kern kern at caltech.edu
Thu Aug 14 20:22:41 EDT 2003


On Thu, Aug 14, 2003 at 03:29:12PM -0600, Fernando Perez wrote:
> Hi all,

[snip]

> - the blitz code, whether via inline() or a purely hand-written extension, 
> is ~2.5 to 3 times slower than innerproduct().  Considering that this code 
> is specialized to a few sizes and data types, this comes as a big surprise. 
> If the only way to get maximum performance with Numpy arrays is to write by 
> hand to the full low-level api, I know that many people will shy away from 
> python for a certain class of projects.  I truly hope I'm missing something 
> here.

I tried your code with g++ 3.3.1, Python 2.3, Numeric 23.0, CVS SciPy on
Debian Linux (kernel 2.4.21), Athlon XP 2100, 512 MB RAM. I tried to
minimize other processes running.

My results with your pristine code aren't nearly as consistent as yours.

As a test, I tried doing the same timings with the standard module
timeit.py (slightly modified to pass in the same arrays for each case).
I obtained the most repeatable (no pun intended) results by using the
Timer.repeat method.  I used it to measure the time it took to run the
code 10 times, then repeated that measurement three times. According to
the timeit.py docs, the minimum of those three measurements is probably
closest to the minimum running time on the machine. By default on
non-Windows platforms, timeit.py uses time.time for its clock. I
repeated the test with inner.clock.

Except for the ndim=2 handwritten case, the times are looking more
realistic, but neither inline nor handwritten code seems to clearly win
over NumPy.

Attached are my_results10min3 (10 reps, minimum of 3 trials, time.time)
and my_results10min3_rusage (10 reps, minimum of 3 trials, inner.clock).

I see the same numerical errors as you, so they are not included in the
output here.

In short, try more repetitions and see if you can reproduce the
consistently 2.5-3 times slower results.

-- 
Robert Kern
kern at caltech.edu

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter
-------------- next part --------------
In timings, t/t_numpy is -1 if t_numpy==0 (too small to measure)

ndim 1 size 7000
Type    t(s)    t/t_numpy
NumPy   7.13062298298
hand    7.40015399456   1.04
inline  7.06557095051   0.99

ndim 2 size 500
Type    t(s)    t/t_numpy
NumPy   2.37221598625
hand    17.6259549856   7.43
inline  2.09143197536   0.88

ndim 3 size 100
Type    t(s)    t/t_numpy
NumPy   11.7430689335
hand    15.2072480917   1.29
inline  11.7263020277   1.00

ndim 4 size 35
Type    t(s)    t/t_numpy
NumPy   7.2849919796
hand    8.51563000679   1.17
inline  7.25194501877   1.00

ndim 5 size 20
Type    t(s)    t/t_numpy
NumPy   11.2177408934
hand    10.9473650455   0.98
inline  11.210021019    1.00

ndim 6 size 13
Type    t(s)    t/t_numpy
NumPy   12.1791609526
hand    13.3315039873   1.09
inline  12.1484740973   1.00
-------------- next part --------------
In timings, t/t_numpy is -1 if t_numpy==0 (too small to measure)

ndim 1 size 7000
Type	t(s)	t/t_numpy
NumPy	6.57
hand	6.86 	1.04
inline	6.48 	0.99

ndim 2 size 500
Type	t(s)	t/t_numpy
NumPy	1.93
hand	8.42 	4.36
inline	2.0 	1.04

ndim 3 size 100
Type	t(s)	t/t_numpy
NumPy	11.43
hand	14.93 	1.31
inline	11.38 	1.00

ndim 4 size 35
Type	t(s)	t/t_numpy
NumPy	6.65
hand	6.82 	1.03
inline	3.01 	0.45

ndim 5 size 20
Type	t(s)	t/t_numpy
NumPy	10.53
hand	10.73 	1.02
inline	10.51 	1.00

ndim 6 size 13
Type	t(s)	t/t_numpy
NumPy	9.83
hand	7.72 	0.79
inline	11.56 	1.18



More information about the SciPy-User mailing list