mirror of
https://github.com/werbenhu/eventbus.git
synced 2025-09-26 20:41:48 +08:00
44 lines
580 B
Go
44 lines
580 B
Go
package eventbus
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func BenchmarkPipePublishSync(b *testing.B) {
|
|
pipe := NewPipe[int]()
|
|
|
|
pipe.Subscribe(pipeHandlerOne)
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
pipe.PublishSync(i)
|
|
}
|
|
}
|
|
|
|
func BenchmarkPipePublish(b *testing.B) {
|
|
pipe := NewPipe[int]()
|
|
|
|
pipe.Subscribe(pipeHandlerOne)
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
pipe.Publish(i)
|
|
}
|
|
}
|
|
|
|
func BenchmarkPipeGoChannel(b *testing.B) {
|
|
ch := make(chan int)
|
|
|
|
go func() {
|
|
for {
|
|
val := <-ch
|
|
pipeHandlerOne(val)
|
|
}
|
|
}()
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
ch <- i
|
|
}
|
|
}
|