Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: Re^2: sorting entires by date

by BrowserUk (Pope)
on Jan 02, 2004 at 01:34 UTC ( #318214=note: print w/ replies, xml ) Need Help??


in reply to Re: Re^2: sorting entires by date
in thread sorting entires by date

In a simplistic benchmark of a thousand records the straight substr $a cmp substr $b comes out over 180% quicker than the ST version. Using a GRT saves another 14%.

The cost of the split in the ST outweights the repeated substr in this case.

#! perl -slw use strict; use Benchmark qw[ cmpthese ]; open IN, '<', 'test.dat' or die $!; our @lines = <IN>; close IN; print "Sorting ", scalar @lines, $/; cmpthese( -3, { ST => q[ my @sorted = map $_->[0], sort{ $a->[4] <=> $b->[4] } map [ $_, split /:/ ], @lines; ], XX => q[ my @sorted = sort{ substr( $a, 19 ) cmp substr( $b, 19 ) } @lines; ], GRT=> q[ my @sorted = map{ substr $_, 10 } sort map{ substr( $_, 20 ) . $_ } @lines; ], }); __END__ P:\test>318176 Sorting 1000 Rate ST XX GRT ST 6.70/s -- -65% -69% XX 19.1/s 186% -- -13% GRT 21.9/s 227% 14% --

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!


Comment on Re: Re: Re^2: sorting entires by date
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://318214]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2015-07-07 02:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (86 votes), past polls