why scipy cause my program slow?

Robert Kern robert.kern at gmail.com
Tue Jan 16 03:33:57 EST 2007


HYRY wrote:
> Why the exec time of test(readdata()) and test(randomdata()) of
> following program is different?
> my test file 150Hz10dB.wav has 2586024 samples, so I set randomdata
> function
> to return a list with 2586024 samples.
> the exec result is:
> 2586024
> <type 'list'>
> 10.8603842736
> 2586024
> <type 'list'>
> 2.16525233979
> test(randomdata()) is 5x faster than test(readdata())
> if I remove "from scipy import *" then I get the following result:
> 2586024
> <type 'list'>
> 2.21851601473
> 2586024
> <type 'list'>
> 2.13885042216
> 
> So, what the problem with scipy?

You're importing (through scipy) numpy's sum() function. The result type of that
function is a numpy scalar type. The set of scalar types was introduced for a
number of reasons, mostly having to do with being able to represent the full
range of numerical datatypes that Python does not have builtin types for.
Unfortunately, the code paths that get executed when arithmetic is performed
sith such scalars are still suboptimal; I believe they are still going through
the full ufunc machinery.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco




More information about the Python-list mailing list