Browse Source

Add benchmarks for subscribe and emitter

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
pull/1681/head
Jakub Sztandera 5 years ago
parent
commit
6500e55492
  1. 33
      p2p/host/eventbus/basic_test.go

33
p2p/host/eventbus/basic_test.go

@ -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…
Cancel
Save