Files
eventbus2/pipe_bench_test.go
2023-08-08 21:08:26 +08:00

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
}
}