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) ...@@ -164,6 +164,7 @@ importpath=$(gomake -s importpath)
echo 'import "./_xtest_"' echo 'import "./_xtest_"'
fi fi
echo 'import "testing"' 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 echo 'import __regexp__ "regexp"' # rename in case tested package is called regexp
# test array # test array
echo echo
...@@ -185,11 +186,26 @@ importpath=$(gomake -s importpath) ...@@ -185,11 +186,26 @@ importpath=$(gomake -s importpath)
done done
echo '}' echo '}'
# body # body
echo echo \
echo 'func main() {' '
echo ' testing.Main(__regexp__.MatchString, tests)' var matchPat string
echo ' testing.RunBenchmarks(__regexp__.MatchString, benchmarks)' var matchRe *__regexp__.Regexp
echo '}'
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 }>_testmain.go
$GC _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