Source file
src/go/types/lookup_test.go
1
2
3
4
5 package types_test
6
7 import (
8 "go/importer"
9 "go/token"
10 "path/filepath"
11 "runtime"
12 "testing"
13
14 . "go/types"
15 )
16
17
18
19
20 func BenchmarkLookupFieldOrMethod(b *testing.B) {
21
22 path := filepath.Join(runtime.GOROOT(), "src", "net", "http")
23
24 fset := token.NewFileSet()
25 files, err := pkgFiles(fset, path)
26 if err != nil {
27 b.Fatal(err)
28 }
29
30 conf := Config{
31 Importer: importer.Default(),
32 }
33
34 pkg, err := conf.Check("http", fset, files, nil)
35 if err != nil {
36 b.Fatal(err)
37 }
38
39 scope := pkg.Scope()
40 names := scope.Names()
41
42
43 lookup := func() {
44 for _, name := range names {
45 typ := scope.Lookup(name).Type()
46 LookupFieldOrMethod(typ, true, pkg, "m")
47 }
48 }
49
50
51
52 lookup()
53
54 b.ResetTimer()
55 for i := 0; i < b.N; i++ {
56 lookup()
57 }
58 }
59
View as plain text