in reply to simple swap...

Possibly because the ($a,$b) = ($b,$a) requires that $a and $b get pushed onto the stack, and then do a list assignment.

However, in Perl 5.6 on my machine here, I get these results:
jeffp@hut [3:04pm] ~ #103> perl -MBenchmark timethese(1_000_000, { 'swap' => q{ ($a,$b) = ($b,$a) }, 'three' => q{ { my $c = $a; $a = $b; $b = $c } }, }); Benchmark: timing 1000000 iterations of swap, three... swap: 17 wallclock secs ( 5.04 usr + 0.00 sys = 5.04 CPU) @ 19 +8449.61/s (n=1000000) three: 29 wallclock secs ( 5.96 usr + 0.01 sys = 5.97 CPU) @ 16 +7539.27/s (n=1000000)
$_="goto+F.print+chop;\n=yhpaj";F1:eval

Replies are listed 'Best First'.
(Robert Flach -- tests aren't equal)RE: Re: simple swap...
by raflach (Pilgrim) on Jul 21, 2000 at 23:18 UTC

    What about testing the number of iterations for a specified amount of runtime, as was done in the original test, as opposed to timing a set number of iterations and checking the time as you did? The first method seems more likely to be accurate to me, and anyway you can't compare the tests unless they are the same, due to the vagaries of benchmark.

    I'd be interested to see the results, but don't have Perl 5.6. Both methods of testing show the traditional method to be faster on 5.005_03.