[Numpy-discussion] sorting and nans, timings.

David Cournapeau david@ar.media.kyoto-u.ac...
Thu Jul 23 02:01:05 CDT 2009


David Cournapeau wrote:
> Charles R Harris wrote:
>   
>> Hi All,
>>
>> I changed the sort routines to sort nans to the end and got some
>> timings. Sorting 100000 random doubles 100 times yields:
>>
>>                current   nan version         
>> quicksort     1.17 sec    1.29 sec
>> mergesort     1.37 sec    1.36 sec
>> heapsort      1.83 sec    2.12 sec
>>
>> Curiously, mergesort doesn't seem to suffer at all. This is using x !=
>> x for nan detection, using npy_isnan is notably slower with my
>> compiler (gcc 4.3.0).  
>>     
>
> That's because glibc isnan is slow :) I was surprised, but our own isnan
> replacement is much faster than the glibc one at  least (like almost
> twice as fast on my P4 machine). Glibc isnan avoids branching, but it
> seems that it tries too hard.
>   

IMO, a 10-15 % increase in time for better nan handling in sort
definitely worths it.

cheers,

David


More information about the NumPy-Discussion mailing list