-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathyaml_func_resolution_context_bench_test.go
More file actions
132 lines (111 loc) · 3.33 KB
/
yaml_func_resolution_context_bench_test.go
File metadata and controls
132 lines (111 loc) · 3.33 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package exec
import (
"testing"
"github.com/cloudposse/atmos/pkg/schema"
)
// BenchmarkResolutionContextPush benchmarks the Push operation.
func BenchmarkResolutionContextPush(b *testing.B) {
ctx := NewResolutionContext()
atmosConfig := &schema.AtmosConfiguration{}
node := DependencyNode{
Component: "test-component",
Stack: "test-stack",
FunctionType: "terraform.state",
FunctionCall: "!terraform.state test-component test-stack output",
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = ctx.Push(atmosConfig, node)
ctx.Pop(atmosConfig)
}
}
// BenchmarkResolutionContextPushPop benchmarks Push followed by Pop.
func BenchmarkResolutionContextPushPop(b *testing.B) {
atmosConfig := &schema.AtmosConfiguration{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
ctx := NewResolutionContext()
node := DependencyNode{
Component: "test",
Stack: "test",
FunctionType: "test",
FunctionCall: "test",
}
_ = ctx.Push(atmosConfig, node)
ctx.Pop(atmosConfig)
}
}
// BenchmarkGetOrCreateResolutionContext benchmarks goroutine-local context retrieval.
func BenchmarkGetOrCreateResolutionContext(b *testing.B) {
ClearResolutionContext()
defer ClearResolutionContext()
// Warm up - create context once.
_ = GetOrCreateResolutionContext()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = GetOrCreateResolutionContext()
}
}
// BenchmarkGetGoroutineID benchmarks goroutine ID extraction.
func BenchmarkGetGoroutineID(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = getGoroutineID()
}
}
// BenchmarkResolutionContextClone benchmarks context cloning.
func BenchmarkResolutionContextClone(b *testing.B) {
ctx := NewResolutionContext()
atmosConfig := &schema.AtmosConfiguration{}
// Add some nodes to make cloning more realistic.
for i := 0; i < 5; i++ {
node := DependencyNode{
Component: "component",
Stack: "stack",
FunctionType: "test",
FunctionCall: "test",
}
_ = ctx.Push(atmosConfig, node)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = ctx.Clone()
}
}
// BenchmarkProcessCustomYamlTagsWithContext benchmarks YAML tag processing with cycle detection.
func BenchmarkProcessCustomYamlTagsWithContext(b *testing.B) {
atmosConfig := &schema.AtmosConfiguration{}
ctx := NewResolutionContext()
input := schema.AtmosSectionMapType{
"string": "value",
"number": 123,
"nested": map[string]any{"key": "value"},
"list": []any{1, 2, 3},
"complex": map[string]any{"deep": map[string]any{"nested": "value"}},
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = ProcessCustomYamlTagsWithContext(atmosConfig, input, "test-stack", nil, ctx, nil)
}
}
// BenchmarkProcessCustomYamlTagsOverhead measures overhead of cycle detection.
func BenchmarkProcessCustomYamlTagsOverhead(b *testing.B) {
atmosConfig := &schema.AtmosConfiguration{}
input := schema.AtmosSectionMapType{
"simple": "value",
}
b.Run("WithoutCycleDetection", func(b *testing.B) {
// Simulate old behavior (direct processing without context).
for i := 0; i < b.N; i++ {
result, _ := processNodes(atmosConfig, input, "test-stack", nil, nil)
_ = result
}
})
b.Run("WithCycleDetection", func(b *testing.B) {
// New behavior with cycle detection.
for i := 0; i < b.N; i++ {
ClearResolutionContext()
_, _ = ProcessCustomYamlTags(atmosConfig, input, "test-stack", nil, nil)
}
})
}