blob: 26be72f9c6267f8486c702710374cd06d0e1e602 [file] [log] [blame]
package benchmarks
import "testing"
const nonBlockingChannelBufferSize = 1024 * 1024
func BenchmarkNonBlockingChannel(b *testing.B) {
iterations := int64(b.N)
b.ReportAllocs()
b.ResetTimer()
channel := make(chan int64, nonBlockingChannelBufferSize)
go func() {
for i := int64(0); i < iterations; {
select {
case channel <- i:
i++
default:
continue
}
}
}()
for i := int64(0); i < iterations; i++ {
select {
case <-channel:
i++
default:
continue
}
}
}