If you have been avoiding using Benchmark because the timethese functions sometimes look a bit complex this code is for you, just add your code and run.

tachyon

use Benchmark; # more iterations = more accuracy (but takes longer) # increase iterations if you get warnings like this: # (warning: too few iterations for a reliable count) $iterations = 10000; $name1 = "Test code 1"; # change name to something more decriptive $code1 = << 'END_CODE1'; # paste first block of code to test here END_CODE1 $name2 = "Test code 2"; # change name to something more decriptive $code2 = << 'END_CODE2'; # paste second block of code to test here END_CODE2 timethese($iterations, {$name1 => $code1, $name2 => $code2} );

Replies are listed 'Best First'.
Re: Benchmark made easy
by bikeNomad (Priest) on Jun 16, 2001 at 02:54 UTC
    I find that it's better to specify seconds instead of iterations:
    timethese(-4, { ... });
    will run each of the code snippets/subs for at least 4 seconds. This way you don't have to adjust iterations.
Re: Benchmark made easy
by Anonymous Monk on Jun 15, 2001 at 23:55 UTC
    How about setting a $SIG{__WARN__} to increase the iterations automatically and start a rematch. A better format would be
    timethese($it,{ "name1",<<code1, #code1 code1 "name2",<<code2, #code2 code2 });
    or
    timethese($it,{ name1=><<code1, #code1 code1 name2=><<code2, #code2 code2 });

      Yeah I thought about this but thought I would just keep it simple. Benchmark is easy to use, the idea was just to make it really easy for people who have not used it before.

      I agree a shorter format would be like what you use but that was not the aim. Personally I usually do it in a one liner.

      Your examples are on record now. TIMTOWTDI

      cheers

      tachyon