-
-
Notifications
You must be signed in to change notification settings - Fork 410
Expand file tree
/
Copy pathbench_test.go
More file actions
40 lines (36 loc) · 826 Bytes
/
bench_test.go
File metadata and controls
40 lines (36 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package ir_test
import (
"testing"
"golang.org/x/tools/go/packages"
"honnef.co/go/tools/go/ir"
)
func BenchmarkSSA(b *testing.B) {
cfg := &packages.Config{
Mode: packages.NeedSyntax | packages.NeedTypes | packages.NeedTypesInfo,
Tests: false,
}
pkgs, err := packages.Load(cfg, "std")
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
prog := ir.NewProgram(pkgs[0].Fset, ir.GlobalDebug)
seen := map[*packages.Package]struct{}{}
var create func(pkg *packages.Package)
create = func(pkg *packages.Package) {
if _, ok := seen[pkg]; ok {
return
}
seen[pkg] = struct{}{}
prog.CreatePackage(pkg.Types, pkg.Syntax, pkg.TypesInfo, true)
for _, imp := range pkg.Imports {
create(imp)
}
}
for _, pkg := range pkgs {
create(pkg)
}
prog.Build()
}
}