mirror of https://github.com/panjf2000/ants.git
add benchmark test
This commit is contained in:
parent
2f6f0de82b
commit
04e6d942d4
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
3
pool.go
3
pool.go
|
@ -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)),
|
||||||
|
|
Loading…
Reference in New Issue