[SciPy-dev] Sorting speed
Travis Oliphant
oliphant.travis at ieee.org
Fri Dec 30 20:21:24 EST 2005
Travis Oliphant wrote:
>
> >>> t1 = timeit.Timer('a.sort()', 'import numarray as na; a =
>na.array(None,shape=10000)')
> >>> t2 = timeit.Timer('a.sort()', 'import scipy as sc; a =
>sc.empty(shape=10000)')
> >>> t1.repeat(3,100)
>[0.26560115814208984, 0.25392889976501465, 0.25759387016296387]
> >>> t2.repeat(3,100)
>[0.66517782211303711, 0.6185309886932373, 0.65760207176208496]
>
>It could be that the 5x numbers were due to the copying of information
>over to a new array. But still, I think 3x leaves room for improvement
>which no doubt specific (rather than generic) sorting algorithms would
>provide.
>
>
In the fixsort branch I've added the necessary tools to fix sort and
argsort incrementally. This means that there is a generic sort
in-place which will be called and works if the compare method is defined.
However, there are hooks for adding new sorting functions and if this
type-specific sort is found it is called. I just tested this on the
example Francesc gave and the type-specific sorting function matches the
speed of numarray. It will not
be difficult to add more type-specific sorting functions.
-Travis
More information about the SciPy-Dev
mailing list