add benchmark test

This commit is contained in:
Andy Pan 2018-05-19 15:57:04 +08:00
parent 2f6f0de82b
commit 04e6d942d4
2 changed files with 23 additions and 3 deletions

View File

@ -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()
}
}

View File

@ -3,7 +3,6 @@ package ants
import ( import (
"runtime" "runtime"
"sync/atomic" "sync/atomic"
"math"
"sync" "sync"
) )
@ -23,7 +22,7 @@ type Pool struct {
func NewPool(size int) *Pool { func NewPool(size int) *Pool {
p := &Pool{ p := &Pool{
capacity: int32(size), capacity: int32(size),
tasks: make(chan f, math.MaxInt32), tasks: make(chan f, 1000),
//workers: &sync.Pool{New: func() interface{} { return &Worker{} }}, //workers: &sync.Pool{New: func() interface{} { return &Worker{} }},
workers: make(chan *Worker, size), workers: make(chan *Worker, size),
destroy: make(chan sig, runtime.GOMAXPROCS(-1)), destroy: make(chan sig, runtime.GOMAXPROCS(-1)),