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