in reply to Benchmarking for loops?

In Benchmark.pm: Does subroutine testing order bias results? it was suggested that the first test is consistently faster, even if the tests are identical.

I added a 2nd "timethese" to your code, with the tests reversed:

Benchmark: timing 30 iterations of a, b... a: 26 wallclock secs (26.64 usr + 0.00 sys = 26.64 CPU) @ 1 +.13/s (n=30) b: 32 wallclock secs (31.64 usr + 0.00 sys = 31.64 CPU) @ 0 +.95/s (n=30) Benchmark: timing 30 iterations of a2, b2... a2: 20 wallclock secs (20.10 usr + 0.00 sys = 20.10 CPU) @ 1 +.49/s (n=30) b2: 28 wallclock secs (27.25 usr + 0.00 sys = 27.25 CPU) @ 1 +.10/s (n=30)

It appears that at least some of the difference is due to the order of the tests.

Replies are listed 'Best First'.
Re^2: Benchmarking for loops?
by graff (Chancellor) on Jul 13, 2004 at 01:37 UTC
    Do you mean to say that sub "a2" is identical to "b", and "b2 is the same code as "a"? (I just wasn't sure what you meant.)
      Yes, exactly. Cut&paste, rename a -> b2, b -> a2.