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