ants/ants_benchmark_test.go

41 lines
623 B
Go
Raw Normal View History

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-19 19:11:51 +03:00
const RunTimes = 10000
2018-05-19 10:57:04 +03:00
func BenchmarkPoolGroutine(b *testing.B) {
for i := 0; i < b.N; i++ {
2018-05-19 19:11:51 +03:00
for j := 0; j < RunTimes; j++ {
ants.Push(demoFunc)
}
ants.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)
// }
//}
2018-05-19 10:57:04 +03:00
func BenchmarkGoroutine(b *testing.B) {
for i := 0; i < b.N; i++ {
2018-05-19 19:11:51 +03:00
var wg sync.WaitGroup
for j := 0; j < RunTimes; j++ {
wg.Add(1)
go func() {
defer wg.Done()
demoFunc()
}()
}
wg.Wait()
2018-05-19 10:57:04 +03:00
}
}