mirror of https://github.com/panjf2000/ants.git
benchmarks updated
This commit is contained in:
parent
b2ab15fa96
commit
d606fb79f6
|
@ -23,9 +23,10 @@
|
|||
package ants_test
|
||||
|
||||
import (
|
||||
"github.com/panjf2000/ants"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/panjf2000/ants"
|
||||
)
|
||||
|
||||
const RunTimes = 1000000
|
||||
|
@ -53,24 +54,29 @@ func BenchmarkGoroutine(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
//func BenchmarkAntsPool(b *testing.B) {
|
||||
// for i := 0; i < b.N; i++ {
|
||||
// var wg sync.WaitGroup
|
||||
// for j := 0; j < RunTimes; j++ {
|
||||
// wg.Add(1)
|
||||
// ants.Push(func() {
|
||||
// demoFunc()
|
||||
// wg.Done()
|
||||
// })
|
||||
// }
|
||||
// wg.Wait()
|
||||
// }
|
||||
//}
|
||||
|
||||
func BenchmarkAntsPoolWithFunc(b *testing.B) {
|
||||
p, _ := ants.NewPoolWithFunc(100000, demoPoolFunc)
|
||||
func BenchmarkAntsPool(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
var wg sync.WaitGroup
|
||||
for j := 0; j < RunTimes; j++ {
|
||||
wg.Add(1)
|
||||
ants.Push(func() {
|
||||
demoFunc()
|
||||
wg.Done()
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAntsPoolWithFunc(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
var wg sync.WaitGroup
|
||||
p, _ := ants.NewPoolWithFunc(100000, func(i interface{}) error {
|
||||
demoPoolFunc(i)
|
||||
wg.Done()
|
||||
return nil
|
||||
})
|
||||
b.ResetTimer()
|
||||
for j := 0; j < RunTimes; j++ {
|
||||
wg.Add(1)
|
||||
p.Serve(RunTimes)
|
||||
|
|
|
@ -23,13 +23,14 @@
|
|||
package ants_test
|
||||
|
||||
import (
|
||||
"github.com/panjf2000/ants"
|
||||
"runtime"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/panjf2000/ants"
|
||||
)
|
||||
|
||||
var n = 1000000
|
||||
var n = 100000
|
||||
|
||||
//func demoFunc() {
|
||||
// var n int
|
||||
|
@ -92,7 +93,7 @@ func demoFunc() {
|
|||
|
||||
func TestAntsPoolWithFunc(t *testing.T) {
|
||||
var wg sync.WaitGroup
|
||||
p, _ := ants.NewPoolWithFunc(100000, func(i interface{}) error {
|
||||
p, _ := ants.NewPoolWithFunc(50000, func(i interface{}) error {
|
||||
demoPoolFunc(i)
|
||||
wg.Done()
|
||||
return nil
|
||||
|
|
|
@ -97,7 +97,7 @@ func (p *PoolWithFunc) scanAndClean() {
|
|||
}()
|
||||
}
|
||||
|
||||
// Push submit a task to pool
|
||||
// Serve submit a task to pool
|
||||
func (p *PoolWithFunc) Serve(args interface{}) error {
|
||||
if atomic.LoadInt32(&p.closed) == 1 {
|
||||
return ErrPoolClosed
|
||||
|
|
Loading…
Reference in New Issue