Commit b8e4fbb7 authored by Rob Pike's avatar Rob Pike

testing: compile regexp only once

The -test.run and -test.bench flags were compilng the regexp for ever test
function, which was mucking up memory profiles.   Add a simple wrapper
to save the compiled state so that the regexp is compiled only once for
each flag.

R=rsc
CC=golang-dev
https://golang.org/cl/4274063
parent d3c61fc2
......@@ -164,6 +164,7 @@ importpath=$(gomake -s importpath)
echo 'import "./_xtest_"'
fi
echo 'import "testing"'
echo 'import __os__ "os"' # rename in case tested package is called os
echo 'import __regexp__ "regexp"' # rename in case tested package is called regexp
# test array
echo
......@@ -185,11 +186,26 @@ importpath=$(gomake -s importpath)
done
echo '}'
# body
echo
echo 'func main() {'
echo ' testing.Main(__regexp__.MatchString, tests)'
echo ' testing.RunBenchmarks(__regexp__.MatchString, benchmarks)'
echo '}'
echo \
'
var matchPat string
var matchRe *__regexp__.Regexp
func matchString(pat, str string) (result bool, err __os__.Error) {
if matchRe == nil || matchPat != pat {
matchPat = pat
matchRe, err = __regexp__.Compile(matchPat)
if err != nil {
return
}
}
return matchRe.MatchString(str), nil
}
func main() {
testing.Main(matchString, tests)
testing.RunBenchmarks(matchString, benchmarks)
}'
}>_testmain.go
$GC _testmain.go
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment