优化代码

This commit is contained in:
GoEdgeLab
2024-04-12 08:41:14 +08:00
parent f10811946d
commit 74161bf685
2 changed files with 42 additions and 20 deletions

View File

@@ -45,3 +45,29 @@ func BenchmarkNewBufferPool2(b *testing.B) {
}
})
}
func BenchmarkNewBufferPool3(b *testing.B) {
var pool = utils.NewBufferPool()
var dataString = strings.Repeat("Hello", 1024)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
var buffer = pool.Get()
buffer.Write([]byte(dataString))
pool.Put(buffer)
}
})
}
func BenchmarkNewBufferPool4(b *testing.B) {
var pool = utils.NewBufferPool()
var dataString = strings.Repeat("Hello", 1024)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
var buffer = pool.Get()
buffer.WriteString(dataString)
pool.Put(buffer)
}
})
}