in reply to Circular buffer instead of shift/push
$ uname -a SunOS xxxxxx 5.6 Generic_105181-15 sun4u sparc SUNW,Ultra-2 $ perl -v This is perl, version 5.005_03 built for sun4-solaris $ perl -MBenchmark -e 'my $m=3; my ($xe,$xp,$xa,$xw)=($m)x4; my @n=(1..$m,0); my @a=("")x$m+1; timethese(-5, { ashiftp => q{ shift @a if $#a==$m }, equaland => q{ $xe < $m and ++$xe or $xe = 0 }, pow2and => q{ scalar(++$xp, $xp &= $m) }, pow2mod => q{ ++$xp & $m }, wheel => q{ $xw = $n[$xw] }, } );' | perl -nawe '$.==1 and print and next;($x=$F[14])=~s/\/.*//;$b||=$x; printf"%12s %12s %5.2fusecs %.2f\n",@F[0,14],1000000/$x,$b/$x' - perl -MBenchmark -e 'my $m=3;my($x,$xe,$xa,$xp,$xw)=($m)x5;my @n=(1..$ +m,0); my (@a,@ai,@ae,@aa,@ap,@aw); @a=@ai=@ae=@aa=@ap=@aw=("")x +$m+1; timethese(-5, { ashpush => q{ shift @a; push @a, $x }, ashifpush => q{ shift @ai if $#ai == $m; push @ai, $x +}, equalandix => q{ $ae[ $xe < $m and ++$xe or $xe = 0 ] = + $xe }, pow2andix => q{ $aa[ ++$xa, $xa &= $m ] = $xa }, pow2modix => q{ $ap[ ++$xp & $m ] = $xw }, wheelix => q{ $aw[ $xw = $n[$xw] ] = $xw }, } );' | perl -nawe '$.==1 and print and next;($x=$F[14])=~s/\/.*//;$b||=$x; printf"%12s %12s %5.2fusecs %.2f\n",@F[0,14],1000000/$x,$b/$x' - > > > > > > > > Benchmark: running ashiftp, equaland, pow2and, pow2mod +,\ wheel, each for at least 5 CPU seconds...\ ashiftp: 280765.34/s 3.56usecs 1.00 equaland: 341119.76/s 2.93usecs 0.82 pow2and: 368781.20/s 2.71usecs 0.76 pow2mod: 568666.50/s 1.76usecs 0.49 wheel: 451163.20/s 2.22usecs 0.62 $ > > > > > > > > > > Benchmark: running ashifpush, ashpush, equalandi +x,\ pow2andix, pow2modix, wheelix, each for at least 5 CPU seconds...\ ashifpush: 115283.93/s 8.67usecs 1.00 ashpush: 223748.51/s 4.47usecs 0.52 equalandix: 198690.04/s 5.03usecs 0.58 pow2andix: 209246.30/s 4.78usecs 0.55 pow2modix: 212778.91/s 4.70usecs 0.54 wheelix: 255846.92/s 3.91usecs 0.45 $ uname -a Linux xxxxxx 2.2.14 #1 SMP Mon Mar 27 16:46:10 EST 2000 i686 unknown $ perl -v This is perl, version 5.005_03 built for i386-linux Benchmark: running ashiftp, equaland, pow2and, pow2mod, wheel,\ each for at least 5 CPU seconds...\ ashiftp: 886579.73/s 1.13usecs 1.00 equaland: 1030440.00/s 0.97usecs 0.86 pow2and: 1309018.03/s 0.76usecs 0.68 pow2mod: 1750427.08/s 0.57usecs 0.51 wheel: 1243260.48/s 0.80usecs 0.71 Benchmark: running ashifpush, ashpush, equalandix, pow2andix, pow2modi +x,\ wheelix, each for at least 5 CPU seconds...\ ashifpush: 237115.60/s 4.22usecs 1.00 ashpush: 437152.00/s 2.29usecs 0.54 equalandix: 548898.80/s 1.82usecs 0.43 pow2andix: 514532.10/s 1.94usecs 0.46 pow2modix: 485667.44/s 2.06usecs 0.49 wheelix: 645636.33/s 1.55usecs 0.37
|
|---|