Skip to content

Instantly share code, notes, and snippets.

@tobyink
Created July 20, 2014 14:24
Show Gist options
  • Save tobyink/e733f839cecc0dd193a6 to your computer and use it in GitHub Desktop.
Save tobyink/e733f839cecc0dd193a6 to your computer and use it in GitHub Desktop.
use strictures;
use Types::Standard -types;
use Benchmark qw(timethis);
{
my $check = Tuple[Int, Str, HashRef];
my $data = [1, "Hello", {}];
my $sub = $check->compiled_check;
warn($check->inline_check(q/$tuple/));
$sub->($data) or die;
timethis 500_000, sub { $sub->($data) };
}
{
my $check = Map[Int, ArrayRef];
my $data = { 1 => [], 2 => [], 3 => [] };
my $sub = $check->compiled_check;
warn($check->inline_check(q/$map/));
$sub->($data) or die;
timethis 500_000, sub { $sub->($data) };
}
__END__
Tuple...
initial speed: 109649.12/s
with xs speed: 1063829.79/s
Map...
initial speed: 40064.10/s
with xs speed: 375939.85/s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment