Why is regular in Pearl 40% faster than in Go? Part of a simple log analysis script.
Perl:
$l=~s/\A([^\s]+?) - - \[([^\]]+?)\] \"([^\"]+?)\" ([^\s]+?) ([^\s]+?) \"([^\"]+?)\"(.+)/$1\n$2\n$3\n$4\n$5\n$6\n$7/g; ($ip, $time, $page, $code, $size, $ref, $agent, $els) = split(/\n/, $l); $page=~s/(GET|HEAD|POST) (.+) (HTTP.+)/$2/; $hash{$page}++; # this faster than Golang (35-40%) Go:
log_format := `^([^ ]+) (-) (-) \[([^\]]+)\] "([^\"]+?)" ([0-9]+) ([^ ]+) "([^"])*" "([^"]*)"` logParser := regexp.MustCompilePOSIX(log_format) log_format_get := `^(GET|HEAD|POST) (.+) (HTTP.+)$` logParserGet := regexp.MustCompilePOSIX(log_format_get) var hash = make(map[string] int); analize1 := func (iline *string) { submatch := logParser.FindSubmatch(strings.TrimSpace(*iline)) if (len(submatch[0])>0){ pg := logParserGet.FindAllStringSubmatch(strings.TrimSpace(submatch[0][5]), 1) if (len(pg)>0){ hash[pg[0][2]]++ } } 
FindAllStringSubmatchscript command inserted into theFindSubmatchandFindAllStringSubmatch"loop" method on Go, which can cause a significant slowdown compared tosplit, which does not generate a loop with a nested script command. Try not to do script cycles if you want to gain time. It can somehow be divided without attachments by correcting the regex expression or somehow differently that the loop would process the core, not the script - then it will be faster. - nick_n_a