why scipy cause my program slow?
Travis Oliphant
oliphant.travis at ieee.org
Wed Jan 17 16:49:08 EST 2007
Robert Kern wrote:
> 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.
This should not be true in the 1.0 release of NumPy. The numpy scalars
do their own math which has less overhead than ufunc-based math. But,
there is still more overhead than with simple floats because mixed-type
arithmetic is handled more generically (the same algorithm covers all
the cases).
The speed could be improved but hasn't been because it is so easy to get
a Python float if you are concerned about speed.
-Travis
More information about the Python-list
mailing list