On 16 February 2014 23:43, <josef.p...@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']:
    print kind
    %timeit np.sort(data, kind=kind)
    %timeit np.argsort(data, kind=kind)


quicksort
1 loops, best of 3: 3.55 s per loop
1 loops, best of 3: 10.3 s per loop
mergesort
1 loops, best of 3: 4.84 s per loop
1 loops, best of 3: 9.49 s per loop
heapsort
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
significant.

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?


/David.
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to