Created
December 8, 2017 08:59
-
-
Save kfly8/baa26c59b0a0685427e08cdd92a55d72 to your computer and use it in GitHub Desktop.
Benchmark Perl Type constraints
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl -w | |
use 5.10.0; | |
use strict; | |
use Benchmark qw(:all); | |
use Data::Validator; | |
use Function::Parameters qw/fun/; | |
use Kavorka fun => { -as => 'kavorka_fun' }; | |
print "perl: $]\n"; | |
print "modules:\n"; | |
foreach my $mod (qw(Data::Validator Function::Parameters Kavorka)) { | |
print "\t", $mod, "/", $mod->VERSION, "\n"; | |
} | |
sub dv_add { | |
state $v = Data::Validator->new( | |
x => { }, | |
y => { }, | |
); | |
my $args = $v->validate(@_); | |
return $args->{x} + $args->{y}; | |
} | |
fun fp_add(:$x, :$y) { | |
return $x + $y; | |
} | |
kavorka_fun ka_add(:$x, :$y) { | |
return $x + $y; | |
} | |
print "without type constraints\n"; | |
cmpthese -1, { | |
'D::Validator' => sub { | |
my $x = dv_add( x => 10, y => 10 ); | |
}, | |
'F::Parameters' => sub { | |
my $x = fp_add( x => 10, y => 10 ); | |
}, | |
'Kavorka' => sub { | |
my $x = ka_add( x => 10, y => 10 ); | |
}, | |
}; | |
# perl: 5.026001 | |
# validation modules: | |
# Data::Validator/1.07 | |
# Function::Parameters/2.001003 | |
# Kavorka/0.037 | |
# without type constraints | |
# Rate Kavorka D::Validator F::Parameters | |
# Kavorka 332262/s -- -15% -72% | |
# D::Validator 390981/s 18% -- -67% | |
# F::Parameters 1183289/s 256% 203% -- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl -w | |
use 5.10.0; | |
use strict; | |
use Benchmark qw(:all); | |
use Types::Standard qw/Value/; | |
use Data::Validator; | |
use Function::Parameters qw/fun/; | |
use Kavorka fun => { -as => 'kavorka_fun' }; | |
print "perl: $]\n"; | |
print "modules:\n"; | |
foreach my $mod (qw(Data::Validator Function::Parameters Kavorka)) { | |
print "\t", $mod, "/", $mod->VERSION, "\n"; | |
} | |
print "type system: "; | |
print 'Types::Standard', '/', Types::Standard->VERSION, "\n"; | |
sub dv_add { | |
state $v = Data::Validator->new( | |
x => Value, | |
y => Value, | |
); | |
my $args = $v->validate(@_); | |
return $args->{x} + $args->{y}; | |
} | |
fun fp_add(Value :$x, Value :$y) { | |
return $x + $y; | |
} | |
kavorka_fun ka_add(Value :$x, Value :$y) { | |
return $x + $y; | |
} | |
print "with type constraints\n"; | |
cmpthese -1, { | |
'D::Validator' => sub { | |
my $x = dv_add( x => 10, y => 10 ); | |
}, | |
'F::Parameters' => sub { | |
my $x = fp_add( x => 10, y => 10 ); | |
}, | |
'Kavorka' => sub { | |
my $x = ka_add( x => 10, y => 10 ); | |
}, | |
}; | |
# perl: 5.026001 | |
# validation modules: | |
# Data::Validator/1.07 | |
# Function::Parameters/2.001003 | |
# Kavorka/0.037 | |
# type system: Types::Standard/1.002001 | |
# with type constraints | |
# Rate D::Validator Kavorka F::Parameters | |
# D::Validator 172031/s -- -20% -62% | |
# Kavorka 214369/s 25% -- -53% | |
# F::Parameters 455903/s 165% 113% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
compared Params::Validate, Smart::Args and Data::Validator
https://github.com/gfx/p5-Data-Validator/blob/master/benchmark/with-type.pl