Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
dankogaiスクリプト tsv の処理対象を $tsv に変えただけ
#!/usr/local/bin/perl
# original: http://blog.livedoor.jp/dankogai/archives/50924886.html
use strict;
use warnings;
use Benchmark qw/timethese cmpthese/;
my $logline =
q{localhost.local - - [04/Oct/2007:12:34:56 +0900] "GET /apache_pb.gif HTTP/1.1" 200 2326 "http://www.dan.co.jp/" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7"};
my (@logline) =
( $logline =~
m!^(.*) (.*) (.*) \[(.*)\] "(.*)" (.*) (.*) "(.*)" "(.*)"! );
my $tsv = join "\t", @logline;
cmpthese(
timethese(
0,
{
rx_naive => sub {
my (@l) =
( $logline =~
m!^(.*) (.*) (.*) \[(.*)\] "(.*)" (.*) (.*) "(.*)" "(.*)"!
);
},
rx_optim => sub {
my (@l) =
( $logline =~
m!^([^\s]*) [^\s]* [^\s]* \[([^]]*)\] "([^"]*)" ([^\s]*) [^\s]* "([^"]*)" "([^"]*)"!
);
},
tsv => sub { my (@l) = split /\t/, $tsv },
}
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment