[Numpy-discussion] 30% speedup when deactivating NumArray.__del__ !!!

Norbert Nemec Norbert.Nemec.list at gmx.de
Fri Jan 28 13:39:12 CST 2005


Hi there,

indeed my suspicion has proven correct:

Am Donnerstag 27 Januar 2005 21:36 schrieb Francesc Altet:
[...]
> For that goal, I selected the next small benchmark:
>
> import numarray
> a = numarray.arange(2000)
> a.shape=(1000,2)
> for j in xrange(1000):
>     for i in range(len(a)):
>         row=a[i]
[...]
> So, I've tried to run the profile module included in the standard
> library in order to see which are the hot spots in python:
>
> $ time ~/python.nobackup/Python-2.4/python -m profile -s time
> create-numarray.py
>          1016105 function calls (1016064 primitive calls) in 25.290 CPU
> seconds
>
>    Ordered by: internal time
>
>    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
>         1   19.220   19.220   25.290   25.290 create-numarray.py:1(?)
>    999999    5.530    0.000    5.530    0.000 numarraycore.py:514(__del__)
>      1753    0.160    0.000    0.160    0.000 :0(eval)
[...]

This benchmark made me suspicious since I had already found it odd before that 
killing a numarray calculation with Ctrl-C nearly always gives a backtrace 
starting in __del__

I did the simple thing: simply comment out the NumArray.__del__ routine 
(numarraycore.py, line 514, current CVS version)

The result is astonishing:

Vanilla numarray:
 nobbi at Marvin:~/tmp $ time python create-array.py

 real    0m9.457s
 user    0m8.851s
 sys     0m0.038s

NumArray.__del__ commented out:
 nobbi at Marvin:~/tmp $ time python create-array.py

 real    0m6.512s
 user    0m6.065s
 sys     0m0.021s

30% speedup !!!!!!

Doing a detailed benchmarking shows similar results.

I don't think I have to go on about this at this point. It seems clear that 
__del__ has to be avoided in such a central position.

Ciao,
Norbert

-- 
_________________________________________Norbert Nemec
         Bernhardstr. 2 ... D-93053 Regensburg
     Tel: 0941 - 2009638 ... Mobil: 0179 - 7475199
           eMail: <Norbert at Nemec-online.de>




More information about the Numpy-discussion mailing list