forked from mirror/ants
update benchmark
This commit is contained in:
parent
315a18400c
commit
3a8cc09373
|
@ -3,12 +3,18 @@ package ants_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
"github.com/panjf2000/ants"
|
"github.com/panjf2000/ants"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const RunTimes = 10000
|
||||||
|
|
||||||
func BenchmarkPoolGroutine(b *testing.B) {
|
func BenchmarkPoolGroutine(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
|
for j := 0; j < RunTimes; j++ {
|
||||||
ants.Push(demoFunc)
|
ants.Push(demoFunc)
|
||||||
}
|
}
|
||||||
|
ants.Wait()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//func BenchmarkPoolGroutine(b *testing.B) {
|
//func BenchmarkPoolGroutine(b *testing.B) {
|
||||||
|
@ -21,6 +27,14 @@ func BenchmarkPoolGroutine(b *testing.B) {
|
||||||
|
|
||||||
func BenchmarkGoroutine(b *testing.B) {
|
func BenchmarkGoroutine(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
go demoFunc()
|
var wg sync.WaitGroup
|
||||||
|
for j := 0; j < RunTimes; j++ {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
demoFunc()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue