github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/go/ir/bench_test.go (about) 1 package ir_test 2 3 import ( 4 "testing" 5 6 "github.com/amarpal/go-tools/go/ir" 7 "golang.org/x/tools/go/packages" 8 ) 9 10 func BenchmarkSSA(b *testing.B) { 11 cfg := &packages.Config{ 12 Mode: packages.NeedSyntax | packages.NeedTypes | packages.NeedTypesInfo, 13 Tests: false, 14 } 15 pkgs, err := packages.Load(cfg, "std") 16 if err != nil { 17 b.Fatal(err) 18 } 19 20 b.ResetTimer() 21 for i := 0; i < b.N; i++ { 22 prog := ir.NewProgram(pkgs[0].Fset, ir.GlobalDebug) 23 seen := map[*packages.Package]struct{}{} 24 var create func(pkg *packages.Package) 25 create = func(pkg *packages.Package) { 26 if _, ok := seen[pkg]; ok { 27 return 28 } 29 seen[pkg] = struct{}{} 30 prog.CreatePackage(pkg.Types, pkg.Syntax, pkg.TypesInfo, true) 31 for _, imp := range pkg.Imports { 32 create(imp) 33 } 34 } 35 for _, pkg := range pkgs { 36 create(pkg) 37 } 38 prog.Build() 39 } 40 }