in reply to Re: Re: Re: Circular buffer instead of shift/push
in thread Circular buffer instead of shift/push
As expected. (Using, 4192 as array size yields only slightly slower resultsmy $m=4; my $x=$m; $m--; my @a=(1..$m,0); timethese(-10, { wheel => sub {$x = $a[$x]}, equaland => sub {++$x==$m and $x=0}, mod2and => sub {$x++; $x &= $m;} } ); Benchmark: running equaland, mod2and, wheel, each for at least 10 CPU +seconds... equaland: 192120.20/s mod2and: 182722.70/s wheel: 170109.49/s
...moves equaland from first to third(!?!).my $m=4; my $x=$m; $m--; my @n=(1..$m,0); my @a=(); timethese(-10, { wheelix => sub {$a[ $x = $n[$x] ] = $x }, equalandix => sub {$a[ ++$x==$m and $x=0 ] = $x }, mod2andix => sub {$a[ ++$x, $x &= $m];} } ); equalandix: 119200.90/s mod2andix: 142736.03/s wheelix: 130290.06/s
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Re: Circular buffer instead of shift/push
by petral (Curate) on Jan 16, 2001 at 09:24 UTC | |
|
Re: Re: Re: Re: Re: Circular buffer instead of shift/push
by petral (Curate) on Jan 16, 2001 at 14:20 UTC |