aboutsummaryrefslogtreecommitdiff
path: root/go/ast/inspector/inspector_test.go
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-03-16 14:15:45 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-03-16 14:15:45 +0000
commitcd3c7908c2ca750b27d330b4d257edc6818c4a5d (patch)
tree194d7b0e539d014393564a256bec571e18d6533a /go/ast/inspector/inspector_test.go
parent3225eca48f7ce16eb31b2dd5a170806c1214a49e (diff)
parent09c5a32afc5b66f28f166a68afe1fc71afbf9b73 (diff)
downloadgolang-x-tools-cd3c7908c2ca750b27d330b4d257edc6818c4a5d.tar.gz
Snap for 9757917 from 09c5a32afc5b66f28f166a68afe1fc71afbf9b73 to build-tools-releasebuild-tools-release
Change-Id: If48e809642d94de846f47e34b88e446095e21aa5
Diffstat (limited to 'go/ast/inspector/inspector_test.go')
-rw-r--r--go/ast/inspector/inspector_test.go44
1 files changed, 41 insertions, 3 deletions
diff --git a/go/ast/inspector/inspector_test.go b/go/ast/inspector/inspector_test.go
index 9e5391896..e88d584b5 100644
--- a/go/ast/inspector/inspector_test.go
+++ b/go/ast/inspector/inspector_test.go
@@ -244,9 +244,11 @@ func typeOf(n ast.Node) string {
// but a break-even point (NewInspector/(ASTInspect-Inspect)) of about 5
// traversals.
//
-// BenchmarkNewInspector 4.5 ms
-// BenchmarkNewInspect 0.33ms
-// BenchmarkASTInspect 1.2 ms
+// BenchmarkASTInspect 1.0 ms
+// BenchmarkNewInspector 2.2 ms
+// BenchmarkInspect 0.39ms
+// BenchmarkInspectFilter 0.01ms
+// BenchmarkInspectCalls 0.14ms
func BenchmarkNewInspector(b *testing.B) {
// Measure one-time construction overhead.
@@ -274,6 +276,42 @@ func BenchmarkInspect(b *testing.B) {
}
}
+func BenchmarkInspectFilter(b *testing.B) {
+ b.StopTimer()
+ inspect := inspector.New(netFiles)
+ b.StartTimer()
+
+ // Measure marginal cost of traversal.
+ nodeFilter := []ast.Node{(*ast.FuncDecl)(nil), (*ast.FuncLit)(nil)}
+ var ndecls, nlits int
+ for i := 0; i < b.N; i++ {
+ inspect.Preorder(nodeFilter, func(n ast.Node) {
+ switch n.(type) {
+ case *ast.FuncDecl:
+ ndecls++
+ case *ast.FuncLit:
+ nlits++
+ }
+ })
+ }
+}
+
+func BenchmarkInspectCalls(b *testing.B) {
+ b.StopTimer()
+ inspect := inspector.New(netFiles)
+ b.StartTimer()
+
+ // Measure marginal cost of traversal.
+ nodeFilter := []ast.Node{(*ast.CallExpr)(nil)}
+ var ncalls int
+ for i := 0; i < b.N; i++ {
+ inspect.Preorder(nodeFilter, func(n ast.Node) {
+ _ = n.(*ast.CallExpr)
+ ncalls++
+ })
+ }
+}
+
func BenchmarkASTInspect(b *testing.B) {
var ndecls, nlits int
for i := 0; i < b.N; i++ {