github.com/webmafia/fast@v0.10.0/pool_test.go (about) 1 package fast 2 3 import ( 4 "sync" 5 "testing" 6 ) 7 8 func BenchmarkPool(b *testing.B) { 9 pool := sync.Pool{ 10 New: func() any { 11 return &struct{}{} 12 }, 13 } 14 15 b.ResetTimer() 16 17 for i := 0; i < b.N; i++ { 18 v := pool.Get() 19 pool.Put(v) 20 } 21 } 22 23 func BenchmarkGenericPool(b *testing.B) { 24 pool := NewPool[struct{}]() 25 26 b.ResetTimer() 27 28 for i := 0; i < b.N; i++ { 29 v := pool.Acquire() 30 pool.Release(v) 31 } 32 } 33 34 func BenchmarkPool_Parallell(b *testing.B) { 35 pool := sync.Pool{ 36 New: func() any { 37 return &struct{}{} 38 }, 39 } 40 41 b.ResetTimer() 42 43 b.RunParallel(func(p *testing.PB) { 44 for p.Next() { 45 v := pool.Get() 46 pool.Put(v) 47 } 48 }) 49 } 50 51 func BenchmarkGenericPool_Parallell(b *testing.B) { 52 pool := NewPool[struct{}]() 53 b.ResetTimer() 54 55 b.RunParallel(func(p *testing.PB) { 56 for p.Next() { 57 v := pool.Acquire() 58 pool.Release(v) 59 } 60 }) 61 }