Skip to content

Instantly share code, notes, and snippets.

@zoul
Created September 15, 2009 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoul/187483 to your computer and use it in GitHub Desktop.
Save zoul/187483 to your computer and use it in GitHub Desktop.
#!/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