Benchmark-CSV
view release on metacpan or search on metacpan
examples/math/math.pl view on Meta::CPAN
$bench->add_instance( 'x / 1' => sub { $large / 1 } );
}
}
*STDERR->print("Running benchmark\n");
*STDERR->autoflush(1);
my $steps = 50;
*STDERR->print( q{[} . ( q[ ] x $steps ) . qq{]\r[} );
for ( 1 .. $steps ) {
$bench->run_iterations( 10_000_000 / $steps );
*STDERR->print("#");
}
*STDERR->print("]\n");
*STDERR->print("Generating plot\n");
system( "gnuplot", "plot.gnuplot" );
*STDERR->print("$imagefile\n");
*STDERR->print("Collating histogram data\n");
system( $^X, './aggregate.pl' );
*STDERR->print("Generating histogram plot\n");
system( 'gnuplot', 'aggregate_histogram.gnuplot' );
examples/mkbatch/mkbatch.pl view on Meta::CPAN
1
EOF
$bench->add_instance( 'unrolled' => $code_a );
$bench->add_instance( 'loop' => $code_b );
*STDERR->print("Running benchmark\n");
*STDERR->autoflush(1);
my $steps = 50;
*STDERR->print( q{[} . ( q[ ] x $steps ) . qq{]\r[} );
for ( 1 .. $steps ) {
$bench->run_iterations( 1_000_000 / $steps );
*STDERR->print("#");
}
*STDERR->print("]\n");
*STDERR->print("Generating plot\n");
system( "gnuplot", "plot.gnuplot" );
*STDERR->print("$imagefile\n");
examples/shuffle/shuffle.pl view on Meta::CPAN
'shuffle keys' => sub {
my @out = shuffle keys %source_hash_clean;
1;
}
);
*STDERR->print("Running benchmark\n");
*STDERR->autoflush(1);
my $steps = 50;
*STDERR->print( q{[} . ( q[ ] x $steps ) . qq{]\r[} );
for ( 1 .. $steps ) {
$bench->run_iterations( 1_000_000 / $steps );
*STDERR->print("#");
}
*STDERR->print("]\n");
*STDERR->print("Generating plot\n");
system( "gnuplot", "plot.gnuplot" );
*STDERR->print("$imagefile\n");
examples/vs_benchmark_pm/vs_benchmark_pm.pl view on Meta::CPAN
*STDERR->autoflush(1);
my $steps = 10;
my $its = 5_000_000 / $steps;
#$bench->{timing_method} = 'hires_cputime_thread';
$bench->{timing_method} = 'times';
*STDERR->print( q{[} . ( q[ ] x $steps ) . qq{]\r[} );
for ( 1 .. $steps ) {
$bench->run_iterations($its);
*STDERR->print("#");
}
*STDERR->print("]\n");
for my $slave (@slaves) {
kill 'HUP', $slave;
}
if ( $ENV{RUN_TWO} ) {
*STDERR->print( q{[} . ( q[ ] x $steps ) . qq{]\r[} );
for ( 1 .. $steps ) {
$bench->run_iterations($its);
*STDERR->print("#");
}
*STDERR->print("]\n");
}
*STDERR->print("Generating plot\n");
system( "gnuplot", "plot.gnuplot" );
*STDERR->print("$imagefile\n");
lib/Benchmark/CSV.pm view on Meta::CPAN
$self->{finalized} = 1;
return;
}
sub _write_result {
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 } );
}
lib/Benchmark/CSV.pm view on Meta::CPAN
use Benchmark::CSV;
my $benchmark = Benchmark::CSV->new(
output => './test.csv',
sample_size => 10,
);
$benchmark->add_instance( 'method_a' => sub {});
$benchmark->add_instance( 'method_b' => sub {});
$benchmark->run_iterations(100_000);
=head1 RATIONALE.
I've long found all the other bench-marking utilities well meaning, but easily confusing.
My biggest misgiving is that they give you one, or two values which it has decided is "the time" your code took,
whether its an average, a median, or some other algorithm, ( Such as in C<Benchmark::Dumb> ), they all amount to basically giving
you a data point, which you have to take for granted.
That data point may also change wildly between test runs due to computer load or other factors.
lib/Benchmark/CSV.pm view on Meta::CPAN
=head2 C<sample_size>
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;
lib/Benchmark/CSV.pm view on Meta::CPAN
my $fh = $bench->output_fh;
Either *STDOUT or an opened C<filehandle>.
=head3 set:C<output_fh>
$bench->output_fh( \*STDERR );
Can be set at any time prior, but not after, running tests.
=head2 C<run_iterations>
Executes the attached tests C<n> times in batches of L<< C<sample_size>|/sample_size >>.
->run_iterations( 10_000_000 );
Because of how it works, simply spooling results at the bottom of the data file, you can call this method
multiple times as necessary and inject more results.
For instance, this could be used to give a progress report.
*STDOUT->autoflush(1);
print "[__________]\r[";
for ( 1 .. 10 ) {
$bench->run_iterations( 1_000_000 );
print "#";
}
print "]\n";
This is also how you can do timed batches:
my $start = [gettimeofday];
# Just execute as much as possible until 10 seconds of wallclock pass.
while( tv_interval( $start, [ gettimeofday ]) < 10 ) {
$bench->run_iterations( 1_000 );
}
=for Pod::Coverage scale_values
=for Pod::Coverage per_second
=for Pod::Coverage timing_method
=head1 AUTHOR
sample_size => 100,
output => $csv,
);
my $x = 946744;
my $y = 7;
$bench->add_instance( 'x + y' => sub { $x + $y } );
$bench->add_instance( 'x - y' => sub { $x - $y } );
$bench->run_iterations(100_000);
my $lines = [ $csv->lines( { chomp => 1 } ) ];
is( $lines->[0], 'x + y,x - y', "Header in place" );
like( $lines->[1], qr/\A\d+[.]\d+,\d+[.]\d+/msx, "Second line matches regex" );
like( $lines->[-1], qr/\A\d+[.]\d+,\d+[.]\d+/msx, "Last line matches regex" );
is( scalar @{$lines}, 1001, "Has 1 line per sample + header" );
( run in 1.321 second using v1.01-cache-2.11-cpan-96521ef73a4 )