github.com/webmafia/fast@v0.10.0/string_buffer_pool_test.go (about) 1 package fast 2 3 import ( 4 "sync" 5 "testing" 6 ) 7 8 func BenchmarkStringBufferPool(b *testing.B) { 9 pool := NewStringBufferPool() 10 11 b.ResetTimer() 12 13 for i := 0; i < b.N; i++ { 14 v := pool.Acquire() 15 pool.Release(v) 16 } 17 } 18 19 func BenchmarkStringBufferAnyPool(b *testing.B) { 20 pool := sync.Pool{ 21 New: func() any { 22 return new(StringBuffer) 23 }, 24 } 25 26 b.ResetTimer() 27 28 for i := 0; i < b.N; i++ { 29 v := pool.Get().(*StringBuffer) 30 v.Reset() 31 pool.Put(v) 32 } 33 }