|
NAMEBenchmark::Dumb - Benchmark.pm compatibility layer for DumbbenchSYNOPSISuse Benchmark::Dumb qw(:all); cmpthese( 0.05, # 5% precision { fast => 'fast code', slow => 'slow code', } ); # etc DESCRIPTIONThis module implements an interface that is similar to the functional interface of the Benchmark module. This module, however, uses the Dumbbench benchmarking tool under the hood. For various reasons, the interface and the output of the benchmark runs are not exactly the same. Among other reasons, you would lose out on some of "Dumbbench"'s advantages.Understanding this documentation requires some familiarity of how "Benchmark.pm" works since it mostly explains how this module is different. Please read the following section carefully to understand the most important differences: Differences to Benchmark.pmThis is a list of differences to the interface and behaviour of the "Benchmark" module. It may not be complete. If so, please let me know.
FUNCTIONSThese functions work mostly (see the $count gotcha above) like the equivalent functions in the "Benchmark" module, but the textual output is different in that it contains estimates of the uncertainties. Some of the style and format options of the original functions are ignored for the time being.I'm quoting the "Benchmark" documentation liberally. timethis(COUNT, CODE, [TITLE, [STYLE]])Time COUNT iterations of CODE. CODE may be a string to eval or a code reference. Unlike with the original "Benchmark", the code will not run in the caller's package. Results will be printed to "STDOUT" as TITLE followed by the "timestr()". TITLE defaults to "timethis COUNT" if none is provided.STYLE determines the format of the output, as described for "timestr()" below. Please read the section on "Differences to Benchmark.pm" for a discussion of how the COUNT parameter is interpreted. Returns a "Benchmark::Dumb" object. timeit(COUNT, CODE)Arguments: COUNT is the number of times to run the loop (see discussion above), and CODE is the code to run. CODE may be either a code reference or a string to be eval'd. Unlike with the original "Benchmark", the code will not run in the caller's package.Returns a "Benchmark::Dumb" object. timethese(COUNT, CODEHASHREF, [STYLE])The CODEHASHREF is a reference to a hash containing names as keys and either a string to eval or a code reference for each value. For each (KEY, VALUE) pair in the CODEHASHREF, this routine will calltimethis(COUNT, VALUE, KEY, STYLE) The routines are called in string comparison order of KEY. The COUNT must be positive or zero. See discussion above. Returns a hash reference of "Benchmark::Dumb" objects, keyed by name. cmpthese(COUNT, CODEHASHREF, [STYLE]) cmpthese(RESULTSHASHREF, [STYLE])Optionally calls "timethese()", then outputs a comparison chart. This:cmpthese( 500.01, { a => "++\$i", b => "\$i *= 2" } ) ; outputs a chart like: Rate/s Precision/s a b a -3.59e+07 6e+06 -- -535.3% b 8.24e+06 220000 -123.0% -- This chart is sorted from slowest to fastest, and shows the percent speed difference between each pair of tests as well as the uncertainties on the rates and the relative speed difference. The uncertainty on a speed difference may be omitted if it is below one tenth of a percent. c<cmpthese> can also be passed the data structure that "timethese()" returns: my $results = timethese( 100.01, { a => "++\$i", b => "\$i *= 2" } ) ; cmpthese( $results ); in case you want to see both sets of results. If the first argument is an unblessed hash reference, that is "RESULTSHASHREF"; otherwise that is "COUNT". Returns a reference to an ARRAY of rows, each row is an ARRAY of cells from the above chart, including labels. This: my $rows = cmpthese( 500.01, { a => '++$i', b => '$i *= 2' }, "none" ); returns a data structure like: [ [ '', 'Rate/s', 'Precision/s', 'a', 'b' ], [ 'a', '-4.43e+06', '120000', '--', '93+-6.9%' ], [ 'b', '-2.294e+06', '52000', '-48.2%', '--' ] ]; METHODSPlease note that while the original "Benchmark" objects practically asked for manual introspection since the API didn't provide convenient access to all information, that practice is frowned upon with "Benchmark::Dumb" objects. You have been warned. If there's a piece of API missing, let me know.There's no public constructor for "Benchmark::Dumb" objects because it doesn't do what the "Benchmark" constructor did: It's not running "time()" for you. name()Returns the name of the benchmark result if any. (Not in "Benchmark".)iters()Returns the number of samples taken.timesum($other_benchmark)Returns a new "Benchmark::Dumb" object that represents the sum of this benchmark and $other_benchmark."timesum($b1, $b2)" was a function in the original "Benchmark" module and may be called as a function on two "Benchmark::Dumb" objects as well. It is available for importing into your namespace. timediff($other_benchmark)Returns a new "Benchmark::Dumb" object that represents the difference between this benchmark and $other_benchmark ("$this-$other")."timediff($b1, $b2)" was a function in the original "Benchmark" module and may be called as a function on two "Benchmark::Dumb" objects as well. It is available for importing into your namespace. timestr()Returns a textual representation of this benchmark."timestr($b)" was a function in the original "Benchmark" module and may be called as a function on a "Benchmark::Dumb" object as well. It is available for importing into your namespace. SEE ALSODumbbenchBenchmark Some of the documentation was taken from the documentation for "Benchmark.pm"'s functions. AUTHORSteffen Mueller, <smueller@cpan.org>COPYRIGHT AND LICENSECopyright (C) 2010, 2012 by Steffen MuellerThis library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.1 or, at your option, any later version of Perl 5 you may have available.
Visit the GSP FreeBSD Man Page Interface. |