From 3a8cc09373f0896d1f794e3ca0230dc997f9c0bd Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sun, 20 May 2018 00:11:51 +0800 Subject: [PATCH] update benchmark --- ants_benchmark_test.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ants_benchmark_test.go b/ants_benchmark_test.go index 2f65def..8246a32 100644 --- a/ants_benchmark_test.go +++ b/ants_benchmark_test.go @@ -3,11 +3,17 @@ package ants_test import ( "testing" "github.com/panjf2000/ants" + "sync" ) +const RunTimes = 10000 + func BenchmarkPoolGroutine(b *testing.B) { for i := 0; i < b.N; i++ { - ants.Push(demoFunc) + for j := 0; j < RunTimes; j++ { + ants.Push(demoFunc) + } + ants.Wait() } } @@ -21,6 +27,14 @@ func BenchmarkPoolGroutine(b *testing.B) { func BenchmarkGoroutine(b *testing.B) { for i := 0; i < b.N; i++ { - go demoFunc() + var wg sync.WaitGroup + for j := 0; j < RunTimes; j++ { + wg.Add(1) + go func() { + defer wg.Done() + demoFunc() + }() + } + wg.Wait() } }