Created
January 5, 2012 16:23
-
-
Save kazeburo/1565974 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| use strict; | |
| use warnings; | |
| use HTTP::Request::Common; | |
| use HTTP::Message::PSGI; | |
| use Plack::Test; | |
| use Plack::Builder; | |
| use Log::Dispatch; | |
| use File::Temp qw/tempfile/; | |
| use Benchmark qw/cmpthese timethese/; | |
| my $app = builder { | |
| enable sub { | |
| my $app = shift; | |
| sub { | |
| my $env = shift; | |
| $app->($env); | |
| } | |
| }; | |
| sub{ [ 200, [], [ "Hello "] ] }; | |
| }; | |
| my $log_app = builder { | |
| enable 'AccessLog', format => "combined", logger => sub {}; | |
| sub{ [ 200, [], [ "Hello "] ] }; | |
| }; | |
| my ($fh,$filename) = tempfile(UNLINK=>1); | |
| my $logger = Log::Dispatch->new( | |
| outputs => [ | |
| [ 'File', min_level => 'debug', filename => $filename ], | |
| ], | |
| ); | |
| my $logdispatch_app = builder { | |
| enable 'AccessLog', format => "combined", logger => sub { $logger->log(level => 'info', message => $_[0]) }; | |
| sub{ [ 200, [], [ "Hello "] ] }; | |
| }; | |
| my $env = req_to_psgi(GET "/"); | |
| cmpthese(timethese(0,{ | |
| 'nolog' => sub { | |
| $app->($env); | |
| }, | |
| 'log' => sub { | |
| $log_app->($env); | |
| }, | |
| 'logdispatch' => sub { | |
| $logdispatch_app->($env); | |
| } | |
| })); | |
| __END__ | |
| Benchmark: running log, logdispatch, nolog for at least 3 CPU seconds... | |
| log: 3 wallclock secs ( 3.14 usr + 0.10 sys = 3.24 CPU) @ 3393.83/s (n=10996) | |
| logdispatch: 3 wallclock secs ( 3.07 usr + 0.13 sys = 3.20 CPU) @ 2130.63/s (n=6818) | |
| nolog: 2 wallclock secs ( 3.06 usr + 0.00 sys = 3.06 CPU) @ 338929.08/s (n=1037123) | |
| Rate logdispatch log nolog | |
| logdispatch 2131/s -- -37% -99% | |
| log 3394/s 59% -- -99% | |
| nolog 338929/s 15807% 9887% -- | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment