News for hackers. Stuff that matters.
Re:Python 3.4.0 released by cschmidt on Monday March 17, 2014 @12:58PM (#7416320)
I haven't got time at the moment, but I would consider contributing an implementation in the long run, if no one else does by then. It just shouldn't be O(n log(n)) when it doesn't have to be.
Re:Python 3.4.0 released by jabagawee on Monday March 17, 2014 @04:11PM (#7417752)
I've just spent the morning implementing various "faster" median algorithms, and it seems that constant factors, function call overhead (for recursive quickselects), etc make all alternative approaches quite slow. The sort-then-select approach is pretty damn fast, especially since I also think / am pretty sure sorted() is implemented in C...

So far I've tried median-of-medians, recursive quickselect, iterative quickselect tracking indices and partitioning in place, and heapq.nlargest. The implementation in Python 3.4.0 is both cleaner/easier to read and faster than anything I can make by an order of magnitude for 10,000 element lists. I'm sure someone else here can do better than me, but (s)he'd have a hard time beating CPython, imo.

Re:Python 3.4.0 released by schmichael on Monday March 17, 2014 @06:21PM (#7418521)
Not only is sorting a Python list implemented in C, the algorithm was sufficiently impressive to be picked up by Java for non-primitives: http://hg.openjdk.java.net/jdk7/tl/jdk/rev/bfd7abda8f79

The reason it's for non-primitives is because it's optimized for sorting lists where comparison is relatively expensive , such as the dereferencing Python does on every item and Java does for non-primitive items.

Thanks for putting the effort in and testing it! Very interesting results.

Re:Python 3.4.0 released by cschmidt on Monday March 17, 2014 @04:34PM (#7417918)
That's very interesting. I used a C implementation of quickselect in that past that was way faster than sorting. That said, my data was also larger than 10,000 elements.

FWIW, here is some old timing data on a 2008 era Mac:

     *  approx timing on my Mac
     *          n, time in ms 
     *         10, <1
     *        100, <1
     *       1000, <1
     *      10000, <1
     *     100000, 30
     *    1000000, 230
     *   10000000, 2530
     *  100000000, 33000
You are probably right that pure python will have trouble competing with a C sort, except for quite large N.
Re:Python 3.4.0 released by pjenvey on Monday March 17, 2014 @07:30PM (#7418839)
Since this is pure Python performance you might want to give the different algorithms a try on PyPy