Benchmark-CSV
view release on metacpan or search on metacpan
lib/Benchmark/CSV.pm view on Meta::CPAN
}
return $self->{timing_method} if $self->{timing_method};
return ( $self->{timing_method} = 'hires_wall' );
}
sub _timing_method {
my ($self) = @_;
return $timing_methods->{ $self->timing_method };
}
sub _compile_timer {
## no critic (Variables::ProhibitUnusedVarsStricter)
my ( $self, $name, $code, $sample_size ) = @_;
## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars);
my $run_one = q[ $code->(); ];
my $run_batch = join qq[\n], map { $run_one } 1 .. $sample_size;
my ( $starter, $stopper, $diff ) = map { $self->_timing_method->{$_} } qw( start stop diff );
my $sub;
if ( $self->per_second and $self->scale_values ) {
$diff = "( ( $diff > 0 ) ? (( 1 / $diff ) * $sample_size ) : 0 )";
}
lib/Benchmark/CSV.pm view on Meta::CPAN
my ( $self, $result ) = @_;
$self->output_fh->printf( "%s\n", join q[,], map { $result->{$_} } sort keys %{$result} );
return;
}
sub run_iterations {
my $nargs = ( my ( $self, $count ) = @_ );
croak 'Arguments missing to ->run_iterations( num )' if $nargs < 2;
$self->_write_header;
my $sample_size = $self->sample_size;
my $timers = {};
for my $instance ( keys %{ $self->{instances} } ) {
$timers->{$instance} = $self->_compile_timer( $instance, $self->{instances}->{$instance}, $sample_size );
}
my @timer_names = keys %{$timers};
for ( 1 .. ( $count / $sample_size ) ) {
$self->_write_result( +{ map { $timers->{$_}->() } shuffle @timer_names } );
}
$self->output_fh->flush;
return;
}
1;
__END__
=pod
lib/Benchmark/CSV.pm view on Meta::CPAN
The number of times to call each sub in a "Sample".
A sample is a block of timed code.
For instance:
->sample_size(4);
->add_instance( x => $y );
->run_iterations(40);
This will create a timer block similar to below.
my $start = time();
# Unrolled, because benchmarking indicated unrolling was faster.
$y->();
$y->();
$y->();
$y->();
return time() - $start;
That block will then be called 10 times ( 40 total code executions batched into 10 groups of 4 )
( run in 1.237 second using v1.01-cache-2.11-cpan-87723dcf8b7 )