NAME Test::Benchmark - Make sure something really is faster SYNOPSIS use Test::More test => 17; use Test::Benchmark; is_faster(-10, sub {...}, sub {...}, "this is faster than that") is_faster(5, -10, sub {...}, sub {...}, "this is 5 times faster than that") is_n_times_faster(5, -10, sub {...}, sub {...}, "this is 5 times faster than that") is_faster(-10, $bench1, $bench2, "res1 was faster than res2"); DESCRIPTION Sometimes you want to make sure that your "faster" algorithm really is faster than the old way. This lets you check. It might also be useful to check that your super whizzo XS or Inline::C version is actually faster. This module is based on the standard Benchmark module. If you have lots of timings to compare and you don't want to keep running the same benchmarks all the time, you can pass in a result object from "Benchmark::timethis()" instead of sub routine reference. USAGE There are 2 functions exported: "is_faster()" and "is_n_times_faster()". Actually "is_n_times_faster()" is redundant because "is_faster()" can do the same thing just by giving it an extra argument. Anywhere you can pass a subroutine reference you can also pass in a Benchmark object. # call as # is_faster($times, $sub1, $sub2, $name) # is_faster($faster, $times, $sub1, $sub2, $name) is_faster() is_faster($times, $sub1, $sub2, $name) is_faster($factor, $times, $sub1, $sub2, $name) This runs each subroutine reference $times times and then compares the results. Instead of either subroutine reference you can pass in a Benchmark object. If you pass in 2 Benchmark objects then $times is irrelevant. If $times is negative then that speicifies a minimum duration for the benchmark rather than a number of iterations (see Benchmark for more details). I strongly recommend you use this feature if you want your modules to still pass tests reliably on machines that are much faster than your own. 10000 iterations may be enough for a reliable benchmark on your home PC but it be just a twinkling in the eye of somebody else's super computer. If the test fails, you will get a diagnostic output showing the benchmark results in the standard Benchmark format. is_n_times_faster() is_n_times_faster($factor, $times, $sub1, $sub2, $name) This is exactly the same as the second form of is_faster but it's just explicit about the "n times" part. DANGERS Benchmarking can be slow so please consider leaving out benchmark tests from your default test suite, perhaps only running them if the user has set a particualr environment variable. Some benchmarks are inherently unreliable. BUGS None that I know of. DEPENDENCIES Benchmark, Test::Builder but they come with most Perl's. HISTORY This came up on the perl-qa mailing list, no one else. SEE ALSO Test::Builder, Benchmark AUTHOR Written by Fergal Daly . COPYRIGHT Copyright 2003 by Fergal Daly . This program is free software and comes with no warranty. It is distributed under the LGPL license. You do not have to accept this license but nothing else gives you the right to use this software. See the file LGPL included in this distribution or http://www.fsf.org/licenses/licenses.html.