mirror of
https://github.com/libp2p/go-eventbus.git
synced 2024-12-25 23:20:07 +08:00
Add benchmarks for subscribe and emitter
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
parent
fc8fa53d99
commit
85cd6aa7c7
@ -449,3 +449,36 @@ func benchMany(bc benchCase) func(*testing.B) {
|
||||
wait.Wait()
|
||||
}
|
||||
}
|
||||
|
||||
var div = 100
|
||||
|
||||
func BenchmarkSubscribe(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N/div; i++ {
|
||||
bus := NewBus()
|
||||
for j := 0; j < div; j++ {
|
||||
bus.Subscribe(new(EventA))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEmitter(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N/div; i++ {
|
||||
bus := NewBus()
|
||||
for j := 0; j < div; j++ {
|
||||
bus.Emitter(new(EventA))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSubscribeAndEmitter(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N/div; i++ {
|
||||
bus := NewBus()
|
||||
for j := 0; j < div; j++ {
|
||||
bus.Subscribe(new(EventA))
|
||||
bus.Emitter(new(EventA))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user