Skip to content

Instantly share code, notes, and snippets.

@hisaichi5518
Created June 3, 2014 08:28
Show Gist options
  • Save hisaichi5518/0b5cb72a6936a25b87c8 to your computer and use it in GitHub Desktop.
Save hisaichi5518/0b5cb72a6936a25b87c8 to your computer and use it in GitHub Desktop.
perl load benchmark
use strict;
use warnings;
use Benchmark qw(:all);
use Plack::Util ();
use Mouse::Util ();
use Class::Load ();
use Module::Load ();
sub load {
my($class, $prefix) = @_;
if ($prefix) {
unless ($class =~ s/^\+// || $class =~ /^$prefix/) {
$class = "$prefix\::$class";
}
}
my $file = $class;
$file =~ s!::!/!g;
return if $INC{"$file.pm"};
require "$file.pm"; ## no critic
return $class;
}
print "without INC{file_path} = undef \n";
cmpthese(-1, {
plack_load => sub {
Plack::Util::load_class("Plack::Handler");
},
mouse_load => sub {
Mouse::Util::load_class("Plack::Handler");
},
class_load => sub {
Class::Load::load_class("Plack::Handler");
},
module_load => sub {
Module::Load::load("Plack::Handler");
},
main_load => sub {
main::load("Plack::Handler");
},
});
print "with INC{file_path} = undef \n";
cmpthese(-1, {
plack_load => sub {
Plack::Util::load_class("Plack::Handler");
$INC{"Plack/Handler.pm"} = undef;
},
mouse_load => sub {
Mouse::Util::load_class("Plack::Handler");
$INC{"Plack/Handler.pm"} = undef;
},
class_load => sub {
Class::Load::load_class("Plack::Handler");
$INC{"Plack/Handler.pm"} = undef;
},
module_load => sub {
Module::Load::load("Plack::Handler");
$INC{"Plack/Handler.pm"} = undef;
},
main_load => sub {
main::load("Plack::Handler");
$INC{"Plack/Handler.pm"} = undef;
},
});
__END__
without INC{file_path} = undef
Rate class_load module_load mouse_load main_load plack_load
class_load 11522/s -- -85% -97% -99% -99%
module_load 78733/s 583% -- -82% -92% -92%
mouse_load 449757/s 3804% 471% -- -55% -56%
main_load 997286/s 8556% 1167% 122% -- -2%
plack_load 1022120/s 8771% 1198% 127% 2% --
with INC{file_path} = undef
Rate class_load module_load mouse_load main_load plack_load
class_load 11016/s -- -87% -97% -99% -99%
module_load 81919/s 644% -- -80% -90% -91%
mouse_load 409599/s 3618% 400% -- -48% -57%
main_load 785983/s 7035% 859% 92% -- -18%
plack_load 954407/s 8564% 1065% 133% 21% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment