Subject: | contains a partial re-implementation of Types::Standard, but way slower |
"Use CPAN modules where feasible."
— Damian Conway, Perl Best Practices (ch 17)
Subject: | dios-benchmark.pl |
use strict;
use warnings;
use Benchmark qw(cmpthese);
use Dios::Types qw(validate);
use Types::Standard qw(ArrayRef Int);
use Type::Tiny::XS qw();
# An array of ArrayRef[Int] of a variety of lengths
my @arrays = map [0..$_], 1..500;
cmpthese(-3, {
dios_types => sub { validate('Array[Int]', $_) for @arrays },
type_tiny => sub { ArrayRef->of(Int)->assert_valid($_) for @arrays },
type_tiny_faster => sub { my $t = ArrayRef->of(Int); $t->assert_valid($_) for @arrays },
});
__END__
Rate dios_types type_tiny type_tiny_faster
dios_types 3.70/s -- -64% -98%
type_tiny 10.2/s 176% -- -95%
type_tiny_faster 204/s 5403% 1894% --