public
Last active

  • Download Gist
Perl eval benchmark
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#!/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% --

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.