From 04e6d942d4c61396da82a8107671ec9ea6365f4d Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sat, 19 May 2018 15:57:04 +0800 Subject: [PATCH] add benchmark test --- ants_benchmark_test.go | 23 ++++++++++++++++++++++- pool.go | 3 +-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ants_benchmark_test.go b/ants_benchmark_test.go index d3306c4..1ce2c52 100644 --- a/ants_benchmark_test.go +++ b/ants_benchmark_test.go @@ -1 +1,22 @@ -package ants +package ants_test + +import ( + "testing" + "github.com/panjf2000/ants" +) + +var size = 1000 + +func BenchmarkPoolGroutine(b *testing.B) { + p := ants.NewPool(size) + b.ResetTimer() + for i := 0; i < b.N; i++ { + p.Push(demoFunc) + } +} + +func BenchmarkGoroutine(b *testing.B) { + for i := 0; i < b.N; i++ { + go demoFunc() + } +} diff --git a/pool.go b/pool.go index 45bf9f3..d058817 100644 --- a/pool.go +++ b/pool.go @@ -3,7 +3,6 @@ package ants import ( "runtime" "sync/atomic" - "math" "sync" ) @@ -23,7 +22,7 @@ type Pool struct { func NewPool(size int) *Pool { p := &Pool{ capacity: int32(size), - tasks: make(chan f, math.MaxInt32), + tasks: make(chan f, 1000), //workers: &sync.Pool{New: func() interface{} { return &Worker{} }}, workers: make(chan *Worker, size), destroy: make(chan sig, runtime.GOMAXPROCS(-1)),