forked from mirror/ants
optimization
This commit is contained in:
parent
04e6d942d4
commit
0c7ba6d3ac
5
ants.go
5
ants.go
|
@ -1,8 +1,6 @@
|
|||
package ants
|
||||
|
||||
import "math"
|
||||
|
||||
const DEFAULT_POOL_SIZE = math.MaxInt32
|
||||
const DEFAULT_POOL_SIZE = 1000
|
||||
|
||||
var defaultPool = NewPool(DEFAULT_POOL_SIZE)
|
||||
|
||||
|
@ -21,4 +19,3 @@ func Cap() int {
|
|||
func Free() int {
|
||||
return defaultPool.Free()
|
||||
}
|
||||
|
||||
|
|
|
@ -5,16 +5,20 @@ import (
|
|||
"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)
|
||||
ants.Push(demoFunc)
|
||||
}
|
||||
}
|
||||
|
||||
//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()
|
||||
|
|
2
pool.go
2
pool.go
|
@ -22,7 +22,7 @@ type Pool struct {
|
|||
func NewPool(size int) *Pool {
|
||||
p := &Pool{
|
||||
capacity: int32(size),
|
||||
tasks: make(chan f, 1000),
|
||||
tasks: make(chan f, size),
|
||||
//workers: &sync.Pool{New: func() interface{} { return &Worker{} }},
|
||||
workers: make(chan *Worker, size),
|
||||
destroy: make(chan sig, runtime.GOMAXPROCS(-1)),
|
||||
|
|
Loading…
Reference in New Issue