mirror of
https://github.com/gissleh/irc.git
synced 2026-10-15 05:12:52 +00:00
make bench test more realistic, as handlers may not be done in the first case when the function returns.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -41,15 +42,24 @@ func BenchmarkHandle(b *testing.B) {
|
|||||||
client := irc.New(context.Background(), irc.Config{})
|
client := irc.New(context.Background(), irc.Config{})
|
||||||
event := irc.NewEvent("test", eventName)
|
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) {
|
b.Run("Emit", func(b *testing.B) {
|
||||||
|
wg.Add(b.N)
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
client.Emit(event)
|
client.Emit(event)
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
})
|
})
|
||||||
|
|
||||||
b.Run("EmitSync", func(b *testing.B) {
|
b.Run("EmitSync", func(b *testing.B) {
|
||||||
|
wg.Add(b.N)
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
client.EmitSync(context.Background(), event)
|
client.EmitSync(context.Background(), event)
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user