优化代码

This commit is contained in:
GoEdgeLab
2021-12-19 11:32:26 +08:00
parent b2fd11f8f4
commit 3ab0f64b18
14 changed files with 154 additions and 66 deletions

View File

@@ -27,6 +27,26 @@ func TestNewBytePool(t *testing.T) {
a.IsTrue(len(pool.c) == 5)
}
func TestBytePool_Memory(t *testing.T) {
var stat1 = &runtime.MemStats{}
runtime.ReadMemStats(stat1)
var pool = NewBytePool(20480, 32*1024)
for i := 0; i < 20480; i++ {
pool.Put(make([]byte, 32*1024))
}
//pool.Purge()
//time.Sleep(60 * time.Second)
runtime.GC()
var stat2 = &runtime.MemStats{}
runtime.ReadMemStats(stat2)
t.Log((stat2.HeapInuse-stat1.HeapInuse)/1024/1024, "MB,", pool.Size(), "slices")
}
func BenchmarkBytePool_Get(b *testing.B) {
runtime.GOMAXPROCS(1)