diff --git a/ants_benchmark_test.go b/ants_benchmark_test.go index 37234fc..6485b61 100644 --- a/ants_benchmark_test.go +++ b/ants_benchmark_test.go @@ -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() }