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

go/scanner: improve variety in benchmarks for file scanning

BenchmarkScanFile was scanning scanner.go, which makes comparison
difficult for a CL modifying that file. That file is also is not
necessarily representative syntax.

Add a few additional files as subtests to provide a larger variety of
metrics.

Change-Id: Ib78303c2546debd84a0b5478ae438ba891d9e6e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/308610
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-04-07 17:43:09 -04:00 committed by Robert Findley
parent 6fa12172d9
commit bc6288794d

View File

@ -889,12 +889,21 @@ func BenchmarkScan(b *testing.B) {
} }
} }
func BenchmarkScanFile(b *testing.B) { func BenchmarkScanFiles(b *testing.B) {
// Scan a few arbitrary large files, and one small one, to provide some
// variety in benchmarks.
for _, p := range []string{
"go/types/expr.go",
"go/parser/parser.go",
"net/http/server.go",
"go/scanner/errors.go",
} {
b.Run(p, func(b *testing.B) {
b.StopTimer() b.StopTimer()
const filename = "scanner.go" filename := filepath.Join("..", "..", filepath.FromSlash(p))
src, err := os.ReadFile(filename) src, err := os.ReadFile(filename)
if err != nil { if err != nil {
panic(err) b.Fatal(err)
} }
fset := token.NewFileSet() fset := token.NewFileSet()
file := fset.AddFile(filename, fset.Base(), len(src)) file := fset.AddFile(filename, fset.Base(), len(src))
@ -910,6 +919,8 @@ func BenchmarkScanFile(b *testing.B) {
} }
} }
} }
})
}
} }
func TestNumbers(t *testing.T) { func TestNumbers(t *testing.T) {