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

•Re^2: Benchmark, -s versus schwartzian

by merlyn (Sage)
on Aug 23, 2004 at 14:28 UTC ( #385082=note: print w/ replies, xml ) Need Help??


in reply to Re: Benchmark, -s versus schwartzian
in thread Benchmark, -s versus schwartzian

Yes, the -s example is a simple example, but doesn't necessarily highlight the ST. The point of the section is to talk about the expense of the comparison function, and one possible solution. I chose -s, because it's easy to talk about, and the ST, because it's the most straightforward general solution. Certainly, in specialized cases, a simple array cache or hash cache or GRT might be better.

In a tutorial, I'm constantly weighing how much or how little to say to accomplish some level of understanding for the tasks at hand. It's trickier than it looks, as anyone who has written training materials can confirm.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.


Comment on •Re^2: Benchmark, -s versus schwartzian
Re^3: Benchmark, -s versus schwartzian
by Anonymous Monk on Aug 23, 2004 at 15:30 UTC
    I'd say that in the general case, GRT will be the fastest solution. If the list is large enough, the bottleneck will be in the sort function, and since the GRT has the simplest sort function possible (namely, the default one), it will outperform anything else.
      By "general", I mean "mortal people can work out a solution for all complex sort criterion". You have to be a frickin' genius to work out a single string for the GRT sometimes. The ST in comparison is always straightforward: construct a list of your sortable keys for a given input item.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

        Why? You can always do the GRT by using only the key (by which you sort) and an index in the string. I think of something like:

        @files = glob("/bin/*"); @sorted = @files[ map { /(\d+)$/g } sort map { sprintf "%012d %d", -s $files[$_], $_ } 0..@files-1]; print "@sorted$/";

        This is of course efficent only because of Perl optimizing the default sort subroutine. Someone who understands perl source well might be able to change sort so that it would optimize sort methods like {$h[$a]<=>$h[$b]} which would give us a possibility to sort even faster like

        my @h = map -s, @files; @results = @files[sort {$h[$a]<=>$h[$b]} 0..@h-1];

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (12)
As of 2014-09-23 13:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (222 votes), past polls