File Coverage

blib/lib/Benchmarks.pm
Criterion Covered Total %
statement 24 25 96.0
branch 15 22 68.1
condition 2 3 66.6
subroutine 5 5 100.0
pod n/a
total 46 55 83.6


line stmt bran cond sub pod time code
1             package Benchmarks;
2 7     7   73249 use strict;
  7         46  
  7         202  
3 7     7   36 use warnings;
  7         12  
  7         195  
4 7     7   4125 use Benchmark qw/ :hireswallclock /;
  7         47903  
  7         42  
5             our $VERSION = '0.11';
6              
7             sub import {
8 7     7   89 my ($class, $code, $count, $style, $title) = @_;
9              
10 7         861 Benchmark->export_to_level(1, $class, ':all');
11              
12 7 100       113 return unless $code;
13 5 50       24 return unless ref $code eq 'CODE';
14              
15 5         20 my ($ret, $runtime_count, $runtime_style, $runtime_title) = $code->();
16              
17 5 50       85 return if !defined $ret;
18              
19 5 50       20 $count = defined($runtime_count) ? $runtime_count
    50          
20             : defined($count) ? $count
21             : -1;
22 5 100       25 $style = defined($runtime_style) ? $runtime_style
    50          
23             : defined($style) ? $style
24             : 'auto';
25 5 100       16 $title = defined($runtime_title) ? $runtime_title
    50          
26             : defined($title) ? $title
27             : undef;
28              
29 5         15 _run_benchmark($count, $ret, $style, $title);
30             }
31              
32             sub _run_benchmark {
33 5     5   14 my ($count, $ret, $style, $title) = @_;
34              
35 5         13 my $ref_ret = ref $ret;
36              
37 5 100 66     49 if ( !$ref_ret || $ref_ret eq 'CODE' ) {
    50          
38 3         9 Benchmark::timethis($count, $ret, $title, $style);
39             }
40             elsif ( $ref_ret eq 'HASH' ) {
41 2         7 Benchmark::cmpthese($count, $ret, $style);
42             }
43             else {
44 0           die "The CODE returned wrong retval.";
45             }
46             }
47              
48             1;
49              
50             __END__