Created
September 15, 2009 17:44
-
-
Save zoul/187483 to your computer and use it in GitHub Desktop.
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/perl | |
use Modern::Perl; | |
use Benchmark 'cmpthese'; | |
sub with_eval | |
{ | |
eval | |
{ | |
my ($a, $b) = (2, 4); | |
my $c = $a+$b; | |
} | |
} | |
sub without_eval | |
{ | |
my ($a, $b) = (2, 4); | |
my $c = $a+$b; | |
} | |
cmpthese(10_000_000, { | |
'with eval' => \&with_eval, | |
'without eval' => \&without_eval | |
}); | |
__DATA__ | |
$ perl eval.pl | |
Rate with eval without eval | |
with eval 1862197/s -- -25% | |
without eval 2493766/s 34% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment