From bf0ffea7dd0bc1c963fd8c2ab7d3122631f3dde6 Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Fri, 17 Jul 2020 19:05:51 +0200 Subject: [PATCH] make bench test more realistic, as handlers may not be done in the first case when the function returns. --- handle_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/handle_test.go b/handle_test.go index 077752f..a5a33be 100644 --- a/handle_test.go +++ b/handle_test.go @@ -4,6 +4,7 @@ import ( "context" "math/rand" "strconv" + "sync" "testing" "time" @@ -41,15 +42,24 @@ func BenchmarkHandle(b *testing.B) { client := irc.New(context.Background(), irc.Config{}) event := irc.NewEvent("test", eventName) + wg := sync.WaitGroup{} + client.AddHandler(func(event2 *irc.Event, client *irc.Client) { + wg.Done() + }) + b.Run("Emit", func(b *testing.B) { + wg.Add(b.N) for n := 0; n < b.N; n++ { client.Emit(event) } + wg.Wait() }) b.Run("EmitSync", func(b *testing.B) { + wg.Add(b.N) for n := 0; n < b.N; n++ { client.EmitSync(context.Background(), event) } + wg.Wait() }) }