develooper Front page | perl.perl5.porters | Postings from July 2004

RE: optimizing Short circuiting sort method based on [M]

From:
Orton, Yves
Date:
July 1, 2004 02:59
Subject:
RE: optimizing Short circuiting sort method based on [M]
Message ID:
E471ED2DFD9353458E8B75FD6D6B03071ADE77@defra1ex4.wcom.de
> I've certainly written plenty of "selection" loops to determine the 
> smallest or largest item in a group.  That's "top 1".

FWIW.

I think this is not unusual nor are top N. The only thing is the later is
IMO more often written like

  @array=(sort @foo)[0..9];

And not like

  ($one,$two,$three)=sort @foo;

As for anything more than a few elements the latter style is a real pain.
Dunno if this is an important consideration but I thought I'd point it out.

So I would say that this optimization is a worthy endeavour. But that's just
me.

BTW, I suspect that this stuff isnt done much in modules but is done a lot
in application code. At least that's where I do it.

Cheers and thanks for the interesting reading and debate,
Yves



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About