thinkeridea / go-extend

go语言扩展包,收集一些常用的操作函数,辅助更快的完成开发工作,并减少重复代码

Home Page:https://pkg.go.dev/github.com/thinkeridea/go-extend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

“动态评估bytes.Buffer的需求的容量,全局共享bytes.Buffer池” 这个pr存在性能测试问题,导致结果存在偏差

thinkeridea opened this issue · comments

#16 在性能测试时,对SyncPool 测试时并没有对 Buffer 进行 Reset 操作,导致大量内存分配,测试结果没有参考性。

在完善测试用例后,以下测试结果并没有相较 sync.Pool 有明显优势,且可能对性能产生影响。

goos: darwin
goarch: amd64
pkg: github.com/thinkeridea/go-extend/pool/benchmark
BenchmarkBufferPool
BenchmarkBufferPool-8                     943312              1065 ns/op               1 B/op          0 allocs/op
BenchmarkBufferSyncPool
BenchmarkBufferSyncPool-8                1000000              1032 ns/op               0 B/op          0 allocs/op
BenchmarkBufferFixedSizePool
BenchmarkBufferFixedSizePool-8          29174670                44.1 ns/op             0 B/op          0 allocs/op
BenchmarkBufferFixedSizeSyncPool
BenchmarkBufferFixedSizeSyncPool-8      38488425                28.1 ns/op             0 B/op          0 allocs/op
PASS
ok      github.com/thinkeridea/go-extend/pool/benchmark 5.236s