Skip to content

Instantly share code, notes, and snippets.

@atoomic
Forked from FGasper/signatures-benchmark.pl
Last active June 11, 2019 16:02
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 atoomic/3b06db8de06f3f74862542826f986eca to your computer and use it in GitHub Desktop.
Save atoomic/3b06db8de06f3f74862542826f986eca to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use v5.20;
use feature qw(signatures);
no warnings qw(experimental::signatures);
require Dumbbench; # use() causes breakage w/ perlcc.
my $bench = Dumbbench->new(
target_rel_precision => 0.005, # seek ~0.5%
initial_runs => 20, # the higher the more reliable
);
use constant MAX => 1_000_000;
$bench->add_instances(
Dumbbench::Instance::PerlSub->new(
name => 'sig',
code => sub { has_sig(1, 2) for 1..MAX; return },
),
Dumbbench::Instance::PerlSub->new(
name => 'unroll',
code => sub { no_sig(1, 2) for 1..MAX; return },
),
Dumbbench::Instance::PerlSub->new(
name => 'stack',
code => sub { no_unroll(1, 2) for 1..MAX; return },
),
Dumbbench::Instance::PerlSub->new(
name => 'sig_add',
code => sub { has_sig_add(1, 2) for 1..MAX; return },
),
Dumbbench::Instance::PerlSub->new(
name => 'unroll_add',
code => sub { no_sig_add(1, 2) for 1..MAX; return },
),
Dumbbench::Instance::PerlSub->new(
name => 'stack_add',
code => sub { no_unroll_add(1, 2) for 1..MAX; return },
),
);
$bench->run();
$bench->report();
sub has_sig_add ($foo, $bar) {
$foo + $bar;
}
sub no_sig_add {
my ($foo, $bar) = @_;
$foo + $bar;
}
sub no_unroll_add {
$_[0] + $_[1];
}
sub has_sig ($foo, $bar) {
}
sub no_sig {
my ($foo, $bar) = @_;
}
sub no_unroll {
}
__END__
## perl 5.28.0
sig: Ran 24 iterations (4 outliers).
sig: Rounded run time per iteration: 2.7561e-01 +/- 1.1e-04 (0.0%)
unroll: Ran 23 iterations (3 outliers).
unroll: Rounded run time per iteration: 2.3930e-01 +/- 1.4e-04 (0.1%)
stack: Ran 23 iterations (2 outliers).
stack: Rounded run time per iteration: 1.17720e-01 +/- 7.3e-05 (0.1%)
sig_add: Ran 25 iterations (4 outliers).
sig_add: Rounded run time per iteration: 3.2155e-01 +/- 2.5e-04 (0.1%)
unroll_add: Ran 26 iterations (6 outliers).
unroll_add: Rounded run time per iteration: 2.8707e-01 +/- 1.2e-04 (0.0%)
stack_add: Ran 21 iterations (1 outliers).
stack_add: Rounded run time per iteration: 1.6839e-01 +/- 1.2e-04 (0.1%)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment