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

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

Nicholas Clark
June 30, 2004 11:58
Re: optimizing Short circuiting sort method based on [M]
Message ID:
On Wed, Jun 30, 2004 at 11:42:44AM -0700, Glenn Linderman wrote:

> Thanks for describing how one would do this with a modified merge sort. 
>  I agree that there would be some benefits to using merge sort, because 
> of perl already using mergesort, but I'm uncertain that any of the code 
> could be reused, without slowing down the "full sort", which wouldn't be 
> a brilliant thing to do.

Indeed not. Slowing down the general case to benefit a special case isn't
going to get in. And I've see no evidence to counter my intuition that this
case of top M is anything but rare.

Does the peephole optimiser currently have any way to optimise

  @a = reverse sort @b


  @a = sort {$b cmp $a} $b;

but without the explicit sort comparison?

Nicholas Clark Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About