in reply to Re: Re: Re: Faster Perl, Good and Bad News
in thread Faster Perl, Good and Bad News
use Benchmark 'cmpthese'; our $a=1; our $b=2; our $tmp; print "Dynamic variables, swap benchmark.\n"; cmpthese -10, {standard => '$::tmp=$::a; $::a=$::b; $::b=$tmp;', list => '($::a,$::b)=($::b,$::a)' }; print "Lexical variables, swap benchmark.\n"; cmpthese -10, { standard_my => sub{my $x=1;my $y=2; my $z =$x; $x=$y +; $y=$z}, standard_local => sub{my $x=1;my $y=2; local $_=$x; $x= +$y; $y=$_}, standard_global => sub{my $x=1;my $y=2; $_=$x; $x=$y; $y +=$_}, list => sub{my $x=1;my $y=2; ($x,$y)=($y,$x)} +, }; __END__ Dynamic variables, swap benchmark. Benchmark: running list, standard, each for at least 10 CPU seconds... list: 11 wallclock secs (10.39 usr + 0.00 sys = 10.39 CPU) @ 66 +4534.94/s (n=6904518) standard: 11 wallclock secs (10.84 usr + 0.00 sys = 10.84 CPU) @ 98 +3324.54/s (n=10662188) Rate list standard list 664535/s -- -32% standard 983325/s 48% -- Lexical variables, swap benchmark. Benchmark: running list, standard_global, standard_local, standard_my, + each for at least 10 CPU seconds... list: 10 wallclock secs (10.13 usr + 0.00 sys = 10.13 CPU) @ 40 +4027.75/s (n=4090781) standard_global: 9 wallclock secs (10.05 usr + 0.00 sys = 10.05 CPU) @ 484686.67/s ( +n=4869647) standard_local: 10 wallclock secs (10.03 usr + 0.00 sys = 10.03 CPU) @ 402621.17/s ( +n=4038693) standard_my: 10 wallclock secs (10.80 usr + 0.00 sys = 10.80 CPU) @ 503630.27/s ( +n=5437696) Rate standard_local list standard_global s +tandard_my standard_local 402621/s -- -0% -17% + -20% list 404028/s 0% -- -17% + -20% standard_global 484687/s 20% 20% -- + -4% standard_my 503630/s 25% 25% 4% + --
Yves / DeMerphq
---
Software Engineering is Programming when you can't. -- E. W. Dijkstra (RIP)
|
|---|