Skip to content

Instantly share code, notes, and snippets.

@tobyink
Created July 21, 2014 12:54
Show Gist options
  • Save tobyink/71eab715ac16178cbcfb to your computer and use it in GitHub Desktop.
Save tobyink/71eab715ac16178cbcfb to your computer and use it in GitHub Desktop.
use strictures;
use Types::Standard -types;
use Types::Common::Numeric -types;
use Benchmark qw(timethis);
{
my $check = ScalarRef | ArrayRef | HashRef;
my $sub = $check->compiled_check;
warn($check->inline_check(q/$ref/));
$sub->([]) or die;
$sub->({}) or die;
$sub->(42) and die;
timethis 500_000, sub { $sub->({}) };
}
{
my $check = PositiveInt &+ Enum[-1,0,1,2];
my $sub = $check->compiled_check;
warn($check->inline_check(q/$i/));
$sub->(1) or die;
$sub->(2) or die;
$sub->(0) and die;
$sub->(-1) and die;
$sub->(42) and die;
timethis 500_000, sub { $sub->(1) };
}
__END__
Union...
initial speed: 255102.04/s
with xs speed: 724637.68/s
Intersection...
initial speed: 370370.37/s
with xs speed: 675675.68/s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment