Skip to content

Instantly share code, notes, and snippets.

@tokuhirom
Created October 16, 2008 12:53
Show Gist options
  • Save tokuhirom/17122 to your computer and use it in GitHub Desktop.
Save tokuhirom/17122 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Benchmark qw/cmpthese/;
sub c1 { $_->[0] }
my @a = map {[rand]} (qw/1/x1000);
cmpthese(
1000 => {
simple => sub {
map { $_->[1] }
sort { $a->[0] <=> $b->[0] }
map { [$_->[0], $_] }
@a
},
"call code" => sub {
map { $_->[1] }
sort { $a->[0] <=> $b->[0] }
map { [c1($_), $_] }
@a
},
},
);
Rate call code simple
call code 207/s -- -13%
simple 238/s 15% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment