in reply to quick sort. How do it faster

G'day builat,

To determine whether some piece of code is faster than another, use the Benchmark module. (In case you didn't know, this is part of the standard Perl distribution: you'll already have it installed.)

Specifically for sorting routines, take a look at both the sort function and the sort pragma. Note the various caveats and warnings, particularly with respect to usage with different Perl versions and deprecation of '_SUBPRAGMA'.

I ran a few tests with the code you've presented here. Your sortQ() routine is roughly an order of magnitude slower than the standard "sort { $a <=> $b } ..." (ascending, numerical) code.

I also found that with (what I'd consider) small arrays of just a few hundred elements, and a relatively high number of duplicates, I got screenfuls of "Deep recursion on subroutine "main::sortQ" ..." messages.

So, test your code with various array sizes, numbers of duplicates (which equates to the range of random numbers) and any other variable factors. Only when you have code that passes your tests should you consider benchmarking: it doesn't matter how fast broken code completes!

-- Ken