No description, website, or topics provided.
Switch branches/tags
Nothing to show
Latest commit 8da2a06 Oct 28, 2016 @tony-o committed on GitHub Merge pull request #11 from zoffixznet/patch-1
Add mandatory "perl" META field
Failed to load latest commit information.
examples Create synopsis.t Oct 13, 2015
lib Apply push/append/slip changes Oct 13, 2015
t s/done/done-testing/ Oct 13, 2015
.travis.yml Create .travis.yml Oct 14, 2015 Add mandatory "perl" META field Oct 26, 2016 travis-ci stuff Oct 14, 2015


Build Status

Benchmark tool for benchmarking how long a block of code runs for X iterations or how many times it can run in a given period.


use Bench;

my $b =;

$b.timethese(1000, {
  first  => sub { sleep .05; },
  second => sub { sleep .005; },
$b.cmpthese(1000, {
  first  => sub { sleep .05; },
  second => sub { sleep .005; },


Timing 1000 iterations of first, second...
     first: 51.5808 wallclock secs @ 19.3871/s (n=1000)
    second: 6.4035 wallclock secs @ 156.1656/s (n=1000)
Timing 1000 iterations of first, second...
     first: 51.5511 wallclock secs @ 19.3982/s (n=1000)
    second: 6.4145 wallclock secs @ 155.8971/s (n=1000)
|        | Rate   | first | second |
| first  | 19.4/s | --    | -88%   |
| second | 156/s  | 704%  | --     |


##.timestr(Array) returns Str

Takes an array returned from any of the following methods and returns a formatted string with the data filled in. The string is similar to below: 6.4145 wallclock secs @ 155.8971/s (n=1000)

##.timeit(Int $iterations, Sub) returns Array

Times a single sub over X iterations. Doesn't output anything by default, just returns an array of time spent and iterations. Use in conjunction with .timestr

##.countit(Rat $time, Sub) returns Array

Returns how many iterations of the Sub it can run in the specified time. Use in conjunction with .timestr

##.timethis(Int $iterations, Sub, Str :$title) returns Array

Runs the specified sub for $iterations and automatically prints out the .timestr. If $iterations is negative or 0 then it runs .countit instead of .timeit

##.timethese(Int $iterations, Hash $Subs) returns Array

Similar to .timethis but the key in the hash becomes the title for the test. An example of the output can be

##.cmpthese(Int $iterations, Hash $Subs) returns Array

Similar to .timethese but it produces a cute little table comparing the results.


Do whatever you want with it.