#!/usr/local/bin/perl
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://pmakino.jp/tdiary/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7"};

my (@logline) = ($logline =~ /^(.*) (.*) (.*) \[(.*)\] "(.*)" (.*) (.*) "(.*)" "(.*)"/);
my $tsv = join "\t", @logline;

cmpthese(
	timethese(
		0,
		{
			rx_naive => sub {
				my (@l) =
					($logline =~
/^(.*) (.*) (.*) \[(.*)\] "(.*)" (.*) (.*) "(.*)" "(.*)"/
					);
			},
			rx_optim_pmakino1 => sub {
				my (@l) =
					($logline =~ 
/^([^ ]*) [^ ]* [^ ]* \[([^]]*)\] "(.*?)" ([^ ]*) [^ ]* "(.*?)" "(.*?)"/
					);
			},
			rx_optim_pmakino2 => sub {
				my (@l) =
					($logline =~
/^([^ ]*) [^ ]* [^ ]* \[([^]]*)\] "((?:\\"|[^"])*)" ([^ ]*) [^ ]* "((?:\\"|[^"])*)" "((?:\\"|[^"])*)"/
					);
			},
			rx_optim_pmakino3 => sub {
				my (@l) =
					($logline =~
/^(.*?) .*? .*? \[(.*?)\] "(.*?)" (.*?) .*? "(.*?)" "(.*?)"/
					);
			},
			rx_optim_myrss1 => sub { # ЋА—pЏг–в‘и‚ ‚и
				my (@l) =
					($logline =~
/^([^\s]*) [^\s]* [^\s]* \[([^]]*)\] "([^"]*)" ([^\s]*) [^\s]* "([^"]*)" "([^"]*)"/
					);
			},
			rx_optim_myrss2 => sub { # ЋА—pЏг–в‘и‚ ‚и
				my (@l) =
					($logline =~
/^([^\s]*) [^\s]* [^\s]* \[([^]]*)\] "([^"]*)" ([^\s]*) [^\s]* "(.*)" "(.*)"/
					);
			},
			rx_optim_myrss3 => sub {
				my (@l) =
					($logline =~
/^([^\s]*) [^\s]* [^\s]* \[([^]]*)\] "(.*?)" ([^\s]*) [^\s]* "(.*?)" "(.*?)"/
					);
			},
			rx_optim_myrss4 => sub {
				my (@l) =
					($logline =~
/^(\S*) \S* \S* \[([^]]*)\] "(.*?)" (\S*) \S* "(.*?)" "(.*?)"/
					);
			},
			rx_optim_myrss5 => sub {
				my (@l) =
					($logline =~
/^([^ ]*) [^ ]* [^ ]* \[([^]]*)\] "(.*?)" ([^ ]*) [^ ]* "(.*?)" "(.*?)"/
					);
			},
			tsv => sub { my (@l) = split /\t/, $logline },
		}
	)
);
