2018-05-19 10:57:04 +03:00
|
|
|
package ants_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"github.com/panjf2000/ants"
|
2018-05-19 19:11:51 +03:00
|
|
|
"sync"
|
2018-05-19 10:57:04 +03:00
|
|
|
)
|
|
|
|
|
2018-05-20 11:22:56 +03:00
|
|
|
const RunTimes = 1000000
|
2018-05-20 06:51:14 +03:00
|
|
|
|
|
|
|
func BenchmarkGoroutine(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
for j := 0; j < RunTimes; j++ {
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
forSleep()
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
}
|
|
|
|
}
|
2018-05-19 19:11:51 +03:00
|
|
|
|
2018-05-19 10:57:04 +03:00
|
|
|
func BenchmarkPoolGroutine(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
2018-05-20 06:51:14 +03:00
|
|
|
var wg sync.WaitGroup
|
2018-05-19 19:11:51 +03:00
|
|
|
for j := 0; j < RunTimes; j++ {
|
2018-05-20 06:51:14 +03:00
|
|
|
wg.Add(1)
|
|
|
|
ants.Push(func() {
|
|
|
|
forSleep()
|
|
|
|
wg.Done()
|
|
|
|
})
|
2018-05-19 19:11:51 +03:00
|
|
|
}
|
2018-05-20 06:51:14 +03:00
|
|
|
wg.Wait()
|
2018-05-19 10:57:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-19 11:10:38 +03:00
|
|
|
//func BenchmarkPoolGroutine(b *testing.B) {
|
|
|
|
// p := ants.NewPool(size)
|
|
|
|
// b.ResetTimer()
|
|
|
|
// for i := 0; i < b.N; i++ {
|
|
|
|
// p.Push(demoFunc)
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|