Created
August 25, 2014 09:30
-
-
Save fujiwara/8ceb4c21b9e8c8008be8 to your computer and use it in GitHub Desktop.
Data::Validator vs Data::Util
This file contains 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
#!/usr/bin/env perl | |
use 5.12.1; | |
use Data::Validator; | |
use Data::Util; | |
use Benchmark qw/ :all /; | |
cmpthese 0, { | |
"Data::Validator" => sub { | |
dv(100); | |
}, | |
"Data::Util" => sub { | |
du(100); | |
}, | |
}; | |
sub dv { | |
my $rule = Data::Validator->new( | |
lv => 'Int', | |
)->with('Sequenced'); | |
my $args = $rule->validate(@_); | |
$args->{lv}; | |
} | |
sub du { | |
my ($lv) = @_; | |
if ( !Data::Util::is_integer($lv) ) { | |
die "Validation failed. $lv is not integer\n"; | |
} | |
return $lv; | |
} |
This file contains 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 b.pl | |
Rate Data::Validator Data::Util | |
Data::Validator 10814/s -- -100% | |
Data::Util 2833220/s 26099% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment