in reply to Re: Re: Stepping through an array
in thread Stepping through an array
our @array = (0..1000000); timethese(-10, { 'Step 1' => 'step1(500000, @::array)', 'Step 2' => 'step2(500000, @::array)', 'Step 3' => 'step3(500000, @::array)' });
we get far more sensible results:
Benchmark: running Step 1, Step 2, Step 3 for at least 10 CPU seconds. +.. Step 1: 10 wallclock secs (10.17 usr + 0.00 sys = 10.17 CPU) @ 5.1 +1/s (n=52) Step 2: 10 wallclock secs (10.00 usr + 0.00 sys = 10.00 CPU) @ 5.1 +0/s (n=51) Step 3: 11 wallclock secs (10.72 usr + 0.00 sys = 10.72 CPU) @ 0.4 +7/s (n=5)
Two things can be learned. First, don't blindly use my. Think whether it's appropriate. Second, always distrust your code if Benchmark returns many iterations per second - especially if you do lots of work during an iteration.
Abigail
|
|---|