[tpm] OID sorting

Fulko Hew fulko.hew at gmail.com
Wed May 6 10:34:40 PDT 2009


On Wed, May 6, 2009 at 1:15 PM, John Macdonald <john at perlwolf.com> wrote:

> Since the numbers are the only significant content of the oid,
>  I wonder whether it would be cheaper to recreate it at the end.
> Sorting with no sort function is faster than having to do
> 2 array subscripts for each compare. (Maybe that was what
> abram_packsort did?)
>
> sub jmm {
>    return
>        map { join( '.', unpack('N*', $_) ) }
>        sort
>        map { pack('N*', split(/\./, $_) ) }
>        @_;
> }
>
> Instead of a 2-element array, I sometimes just use a single
> string, consisting of a leading portion which is directly
> sortable, if necessary a marker, and finally the original
> string.  The final map just removes the leading string (and
> the marker).
>


OK... We have a new leader!

John is now in the lead and has passed the competition with
the fastest, and arguably fairly readable version provided.

The benchmark places it (with other versions removed for clarity):

                   s/iter    Improvement
abram_whilecmp       7.08             --
fulko_sort           1.11           537%
abram_nounpacksort  0.907           681%
jmm                 0.803           782%
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20090506/8cd80f66/attachment-0001.html>


More information about the toronto-pm mailing list