Skip to content

Instantly share code, notes, and snippets.

@kentfredric
Created August 29, 2016 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kentfredric/0c7a0dbb0c79f062ac07796ae4604ca3 to your computer and use it in GitHub Desktop.
Save kentfredric/0c7a0dbb0c79f062ac07796ae4604ca3 to your computer and use it in GitHub Desktop.
#!perl
use strict;
use warnings;
use Dumbbench;
use Time::HiRes qw( gettimeofday );
my $bench = Dumbbench->new(
target_rel_precision => 0.005, # seek ~0.5%
initial_runs => 20, # the higher the more reliable
);
my $iruns = 1e5;
$bench->add_instances(
Dumbbench::Instance::PerlSub->new(
name => "noop",
code => sub {
for ( 1 .. $iruns ) {
my $value = [ $_, $_ ];
defined $value and next;
}
}
),
Dumbbench::Instance::PerlSub->new(
name => "gettimeofday",
code => sub {
for ( 1 .. $iruns ) {
my $value = [gettimeofday];
defined $value and next;
}
}
)
);
$bench->run;
$bench->report;
noop: 3.6766e-02 ± 2.1e-05 per 1e5 its
gettimeofday 15.1750e-02 ± 28.0e-05 per 1e5 its
= 11.4984e-02 per 1e5 its
= 11.4984e-07 per it
noop: Ran 31 iterations (11 outliers).
noop: Rounded run time per iteration: 3.6766e-02 +/- 2.1e-05 (0.1%)
gettimeofday: Ran 28 iterations (8 outliers).
gettimeofday: Rounded run time per iteration: 1.5175e-01 +/- 2.8e-04 (0.2%)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment