forked from mirror/ants
update benchmark
This commit is contained in:
parent
ffe56cc35d
commit
004caa6636
|
@ -30,6 +30,7 @@ import (
|
|||
)
|
||||
|
||||
const RunTimes = 1000000
|
||||
const loop = 1000000
|
||||
|
||||
func demoPoolFunc(args interface{}) error {
|
||||
m := args.(int)
|
||||
|
@ -41,14 +42,13 @@ func demoPoolFunc(args interface{}) error {
|
|||
}
|
||||
|
||||
func BenchmarkGoroutine(b *testing.B) {
|
||||
b.N = 1
|
||||
for i := 0; i < b.N; i++ {
|
||||
var wg sync.WaitGroup
|
||||
b.ResetTimer()
|
||||
for j := 0; j < RunTimes; j++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
demoPoolFunc(RunTimes)
|
||||
demoPoolFunc(loop)
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
|
@ -56,19 +56,19 @@ 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 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++ {
|
||||
|
@ -81,7 +81,7 @@ func BenchmarkAntsPoolWithFunc(b *testing.B) {
|
|||
b.ResetTimer()
|
||||
for j := 0; j < RunTimes; j++ {
|
||||
wg.Add(1)
|
||||
p.Serve(RunTimes)
|
||||
p.Serve(loop)
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue