Updated channels to count sequence values.
diff --git a/benchmarks/blocking_channel_test.go b/benchmarks/blocking_channel_test.go
index 2070631..2223efb 100644
--- a/benchmarks/blocking_channel_test.go
+++ b/benchmarks/blocking_channel_test.go
@@ -2,14 +2,12 @@
import "testing"
-const blockingChannelBufferSize = 1024 * 1024
-
func BenchmarkBlockingChannel(b *testing.B) {
iterations := int64(b.N)
b.ReportAllocs()
b.ResetTimer()
- channel := make(chan int64, blockingChannelBufferSize)
+ channel := make(chan int64, 1024*16)
go func() {
for i := int64(0); i < iterations; i++ {
channel <- i
@@ -17,6 +15,9 @@
}()
for i := int64(0); i < iterations; i++ {
- <-channel
+ msg := <-channel
+ if msg != i {
+ panic("Out of sequence")
+ }
}
}
diff --git a/benchmarks/non_blocking_channel_test.go b/benchmarks/non_blocking_channel_test.go
index 26be72f..0867462 100644
--- a/benchmarks/non_blocking_channel_test.go
+++ b/benchmarks/non_blocking_channel_test.go
@@ -2,14 +2,12 @@
import "testing"
-const nonBlockingChannelBufferSize = 1024 * 1024
-
func BenchmarkNonBlockingChannel(b *testing.B) {
iterations := int64(b.N)
b.ReportAllocs()
b.ResetTimer()
- channel := make(chan int64, nonBlockingChannelBufferSize)
+ channel := make(chan int64, 1024*16)
go func() {
for i := int64(0); i < iterations; {
select {
@@ -21,10 +19,14 @@
}
}()
- for i := int64(0); i < iterations; i++ {
+ for i := int64(0); i < iterations; {
select {
- case <-channel:
- i++
+ case msg := <-channel:
+ if msg != i {
+ panic("Out of sequence")
+ } else {
+ i++
+ }
default:
continue
}