develooper Front page | perl.perl5.porters | Postings from September 2000

Re: the door is closed.

Thread Previous
From:
Ben Tilly
Date:
September 2, 2000 03:55
Subject:
Re: the door is closed.
Message ID:
LAW2-F290ojJoPUprhu00000dea@hotmail.com
Jarkko Hietaniemi wrote:
>
>On Fri, Sep 01, 2000 at 08:23:16PM -0400, Ben Tilly wrote:
> > >Theory: only documentation fixes can any more get in.
> >
> > Well this is a documentation fix, based on benchmark results at
> >
> > http://www.perlmonks.org/index.pl?node_id=30243
> >
> > It seems that the test is a performance loss, and at a guess that
> > Tye McQueen made (which I suspect is correct), the only reason
> > for it is that if you swap an element with itself with an xor,
>
>With an xor...where is this xor...?

Why do you think I proposed the change? :-)

In C you might swap with:

    array[i] ^= array[j] ^= array[i] ^= array[j];

in which case you would really need that test because if i was j
this would zero out the entry.

In Perl using slices the test is not needed and slows you down.
If the array has $n elements you get to break out early roughly
log($n) times and have to pay the price of the check $n times.

> > bad things happen.

Specifically you can lose entries of the array.

> > Cheers,
> > Ben
> >
> > --- perlfaq4.pod.bak    Fri Sep  1 09:03:28 2000
> > +++ perlfaq4.pod        Fri Sep  1 09:04:11 2000
> > @@ -1189,7 +1189,6 @@
> >          my $i;
> >          for ($i = @$array; --$i; ) {
> >              my $j = int rand ($i+1);
> > -            next if $i == $j;
> >              @$array[$i,$j] = @$array[$j,$i];
> >          }
> >      }
>
Cheers,
Ben
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at 
http://profiles.msn.com.


Thread Previous


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