[Numpy-discussion] argsort speed
davidmenhur at gmail.com
Sun Feb 16 18:12:27 EST 2014
On 16 February 2014 23:43, <josef.pktd at gmail.com> wrote:
> What's the fastest argsort for a 1d array with around 28 Million
> elements, roughly uniformly distributed, random order?
On numpy latest version:
for kind in ['quicksort', 'mergesort', 'heapsort']:
%timeit np.sort(data, kind=kind)
%timeit np.argsort(data, kind=kind)
1 loops, best of 3: 3.55 s per loop
1 loops, best of 3: 10.3 s per loop
1 loops, best of 3: 4.84 s per loop
1 loops, best of 3: 9.49 s per loop
1 loops, best of 3: 12.1 s per loop
1 loops, best of 3: 39.3 s per loop
It looks quicksort is quicker sorting, but mergesort is marginally faster
sorting args. The diference is slim, but upon repetition, it remains
Why is that? Probably part of the reason is what Eelco said, and part is
that in sort comparison are done accessing the array elements directly, but
in argsort you have to index the array, introducing some overhead.
I seem unable to find the code for ndarray.sort, so I can't check. I have
tried to grep it tring all possible combinations of "def ndarray",
"self.sort", etc. Where is it?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion