Skip to content

Instantly share code, notes, and snippets.

@mix3
Created August 22, 2011 09:07
Show Gist options
  • Save mix3/1161981 to your computer and use it in GitHub Desktop.
Save mix3/1161981 to your computer and use it in GitHub Desktop.
eval_goto_bench.pl
use Benchmark qw(cmpthese timethese);
cmpthese timethese(100000, {
eval => sub {
eval {
die;
};
if($@){}
},
goto => sub {
goto LABEL;
LABEL:
},
});
@mix3
Copy link
Author

mix3 commented Aug 22, 2011

$ perl eval_goto_bench.pl

Benchmark: timing 100000 iterations of eval, goto...
      eval:  0 wallclock secs ( 0.15 usr +  0.00 sys =  0.15 CPU) @ 666666.67/s (n=100000)
            (warning: too few iterations for a reliable count)
      goto:  0 wallclock secs ( 0.01 usr +  0.00 sys =  0.01 CPU) @ 10000000.00/s (n=100000)
            (warning: too few iterations for a reliable count)
           Rate  eval  goto
eval   666667/s    --  -93%
goto 10000000/s 1400%    --

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment