Skip to content

Instantly share code, notes, and snippets.

@toritori0318
Created July 4, 2011 10:58
Show Gist options
  • Select an option

  • Save toritori0318/1063209 to your computer and use it in GitHub Desktop.

Select an option

Save toritori0318/1063209 to your computer and use it in GitHub Desktop.
perlのログモジュールベンチマークスクリプト
use strict;
use warnings;
use Benchmark qw(timethese cmpthese);
my $count = shift || 1;
my $message = 'Blah, blah';
#perl -MV=Log::Dispatch,Log::Handler,Log::Log4perl,Log::Minimal
######## Log::Dispatch
use Log::Dispatch;
my $log = Log::Dispatch->new(
outputs => [
[
'File',
filename => 'logfile1',
min_level => 'debug',
newline => 1,
],
],
);
######## Log::Handler
use Log::Handler;
my $logh = Log::Handler->new();
$logh->add(
file => {
filename => "logfile2",
maxlevel => "debug",
minlevel => "warning",
message_layout => "%m"
}
);
######## Log::Log4perl
use Log::Log4perl;
Log::Log4perl->init("log4perl.conf");
my $log4 = Log::Log4perl::get_logger("mylogger");
######## Log::Minimal
use Log::Minimal;
open my $fh, '>', 'logfile3';
select( ( select($fh), $| = 1 )[0] );
local $Log::Minimal::PRINT = sub {
my ( $time, $type, $message, $trace) = @_;
print $fh "$message\n";
};
# benchmark
my $comp = timethese(
$count,
{
log_dispatch => \&log_dispatch,
log_handler => \&log_handler,
log4perl => \&log4perl,
log_minimal => \&log_minimal,
}
);
cmpthese $comp;
sub log_dispatch {
$log->info($message);
}
sub log_handler {
$logh->info($message);
}
sub log4perl {
$log4->info($message);
}
sub log_minimal {
infof($message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment