diff --git a/utils/concurrent/pool_benchmark_test.go b/utils/concurrent/pool_benchmark_test.go new file mode 100644 index 0000000..692089a --- /dev/null +++ b/utils/concurrent/pool_benchmark_test.go @@ -0,0 +1,26 @@ +package concurrent_test + +import ( + "github.com/kercylan98/minotaur/utils/concurrent" + "testing" +) + +func BenchmarkPool_Get2Put(b *testing.B) { + var pool = concurrent.NewPool[map[string]int](func() *map[string]int { + return &map[string]int{} + }, func(data *map[string]int) { + for k := range *data { + delete(*data, k) + } + }) + + b.ResetTimer() + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + msg := pool.Get() + pool.Release(msg) + } + }) + b.StopTimer() + b.ReportAllocs() +} diff --git a/utils/concurrent/pool_test.go b/utils/concurrent/pool_test.go index 03410c8..0c8c895 100644 --- a/utils/concurrent/pool_test.go +++ b/utils/concurrent/pool_test.go @@ -1,32 +1 @@ package concurrent_test - -import ( - "github.com/kercylan98/minotaur/utils/concurrent" - "github.com/kercylan98/minotaur/utils/times" - "testing" - "time" -) - -func TestPool_EAC(t *testing.T) { - var p = concurrent.NewPool[int](10, func() int { - return 0 - }, func(data int) { - }) - - go func() { - for i := 0; i < 1000; i++ { - go func() { - for { - p.Release(p.Get()) - } - }() - } - }() - - go func() { - time.Sleep(2 * time.Second) - p.EAC(2048) - }() - - time.Sleep(100 * times.Day) -}