]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: fix missing Importer for TestBenchmark
authorRob Findley <rfindley@google.com>
Wed, 19 Aug 2020 02:29:22 +0000 (22:29 -0400)
committerRobert Findley <rfindley@google.com>
Thu, 27 Aug 2020 17:57:10 +0000 (17:57 +0000)
TestBenchmark is broken due to lack of a Config.Importer, but
unfortunately fails silently due to an unchecked error.

Fix the importer and check the error. Also improve the output to include
allocation stats.

Finally, don't run TestBenchmark on go/types by default. If the
benchmark is being used during a refactoring of go/types itself, results
for go/types will not be comparable.

Change-Id: Ib6bdb6807403b3ec99762f535e2496c94bd9b6e0
Reviewed-on: https://go-review.googlesource.com/c/go/+/249517
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
src/go/types/self_test.go

index 10ad06fbca16475b5c55bf471c81291ba8712f97..04c9cd3458e8b365554af5847bf5974a7d76e7cc 100644 (file)
@@ -47,8 +47,13 @@ func TestBenchmark(t *testing.T) {
        // We're not using testing's benchmarking mechanism directly
        // because we want custom output.
 
-       for _, p := range []string{"types", "constant", filepath.Join("internal", "gcimporter")} {
-               path := filepath.Join("..", p)
+       for _, p := range []string{
+               "net/http",
+               "go/parser",
+               "go/constant",
+               filepath.Join("go", "internal", "gcimporter"),
+       } {
+               path := filepath.Join("..", "..", p)
                runbench(t, path, false)
                runbench(t, path, true)
                fmt.Println()
@@ -64,8 +69,13 @@ func runbench(t *testing.T, path string, ignoreFuncBodies bool) {
 
        b := testing.Benchmark(func(b *testing.B) {
                for i := 0; i < b.N; i++ {
-                       conf := Config{IgnoreFuncBodies: ignoreFuncBodies}
-                       conf.Check(path, fset, files, nil)
+                       conf := Config{
+                               IgnoreFuncBodies: ignoreFuncBodies,
+                               Importer:         importer.Default(),
+                       }
+                       if _, err := conf.Check(path, fset, files, nil); err != nil {
+                               t.Fatal(err)
+                       }
                }
        })
 
@@ -77,10 +87,9 @@ func runbench(t *testing.T, path string, ignoreFuncBodies bool) {
        })
 
        d := time.Duration(b.NsPerOp())
-       fmt.Printf(
-               "%s: %s for %d lines (%d lines/s), ignoreFuncBodies = %v\n",
-               filepath.Base(path), d, lines, int64(float64(lines)/d.Seconds()), ignoreFuncBodies,
-       )
+       fmt.Printf("%s (ignoreFuncBodies = %v):\n", filepath.Base(path), ignoreFuncBodies)
+       fmt.Printf("\t%s for %d lines (%.0f lines/s)\n", d, lines, float64(lines)/d.Seconds())
+       fmt.Printf("\t%s\n", b.MemString())
 }
 
 func pkgFiles(fset *token.FileSet, path string) ([]*ast.File, error) {