mirror of
https://github.com/golang/go
synced 2024-09-30 04:24:29 -06:00
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
This commit is contained in:
parent
d3c61fc214
commit
b8e4fbb79c
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user