From 0081fc69204b557dc7faaa51e7132ee424110231 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 21 May 2019 12:42:42 -0700 Subject: [PATCH] benchmark against alloc --- pool_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pool_test.go b/pool_test.go index f517167..1941144 100644 --- a/pool_test.go +++ b/pool_test.go @@ -139,11 +139,27 @@ func BenchmarkPool(b *testing.B) { i = i << 1 } b := p.Get(i) + b[0] = byte(i) p.Put(b) } }) } +func BenchmarkAlloc(b *testing.B) { + b.RunParallel(func(pb *testing.PB) { + i := 7 + for pb.Next() { + if i > 1<<20 { + i = 7 + } else { + i = i << 1 + } + b := make([]byte, i) + b[1] = byte(i) + } + }) +} + func BenchmarkPoolOverlflow(b *testing.B) { var p BufferPool b.RunParallel(func(pb *testing.PB) { -- GitLab