From 004caa6636017f14c7ea19f24d1cce2b4b10df24 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Wed, 23 May 2018 00:01:10 +0800 Subject: [PATCH] update benchmark --- ants_benchmark_test.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) 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() }