Skip to content

Commit 5e29312

Browse files
committed
fix: Update memory allocation in benchmarks to use pointer for improved performance - Change data allocation in sync.Pool to return a pointer and adjust usage accordingly
1 parent c3c6b88 commit 5e29312

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pkg/performance/benchmarks_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,16 @@ func BenchmarkMemoryAllocation(b *testing.B) {
139139
b.Run("WithPool", func(b *testing.B) {
140140
pool := &sync.Pool{
141141
New: func() interface{} {
142-
return make([]byte, 1024)
142+
data := make([]byte, 1024)
143+
return &data
143144
},
144145
}
145146

146147
b.ResetTimer()
147148
for i := 0; i < b.N; i++ {
148-
data := pool.Get().([]byte)
149+
data := pool.Get().(*[]byte)
149150
// Simulate work
150-
_ = data
151+
_ = *data
151152
pool.Put(data)
152153
}
153154
})

0 commit comments

Comments
 (0)