1
0
mirror of https://github.com/golang/go synced 2024-11-11 22:20:22 -07:00

go/parser: add benchmarks for syntax-only parsing and object resolution

Change-Id: I73d1b2d18ab4051443d66c60df493d1163d0ba3f
Reviewed-on: https://go-review.googlesource.com/c/go/+/306150
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Rob Findley 2021-03-30 08:26:24 -04:00 committed by Robert Findley
parent 88a8a27056
commit 6fa12172d9

View File

@ -10,6 +10,8 @@ import (
"testing"
)
// TODO(rFindley): use a testdata file or file from another package here, to
// avoid a moving target.
var src = readFile("parser.go")
func readFile(filename string) []byte {
@ -28,3 +30,27 @@ func BenchmarkParse(b *testing.B) {
}
}
}
func BenchmarkParseOnly(b *testing.B) {
b.SetBytes(int64(len(src)))
for i := 0; i < b.N; i++ {
if _, err := ParseFile(token.NewFileSet(), "", src, ParseComments|SkipObjectResolution); err != nil {
b.Fatalf("benchmark failed due to parse error: %s", err)
}
}
}
func BenchmarkResolve(b *testing.B) {
b.SetBytes(int64(len(src)))
for i := 0; i < b.N; i++ {
b.StopTimer()
fset := token.NewFileSet()
file, err := ParseFile(fset, "", src, SkipObjectResolution)
if err != nil {
b.Fatalf("benchmark failed due to parse error: %s", err)
}
b.StartTimer()
handle := fset.File(file.Package)
resolveFile(file, handle, nil)
}
}