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

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

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


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

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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About