Skip to content

Instantly share code, notes, and snippets.

@gfx
Created November 1, 2009 07:49
Show Gist options
  • Save gfx/223428 to your computer and use it in GitHub Desktop.
Save gfx/223428 to your computer and use it in GitHub Desktop.
#!perl -w
use strict;
use Benchmark qw(:all);
use Sub::Call::Tail;
sub foo{ 1 }
sub tailcall{
tail foo(1, 2, 3);
}
sub do_goto{
@_ = (1, 2, 3);
goto &foo;
}
sub normal{
foo(1, 2, 3);
}
cmpthese -1 => {
tail => sub{
tailcall();
},
goto => sub{
do_goto();
},
normal => sub{
normal();
},
};
$ perl -Mblib benchmark/benchmark.pl
Rate goto tail normal
goto 562196/s -- -66% -70%
tail 1635885/s 191% -- -13%
normal 1890462/s 236% 16% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment