Skip to content

Instantly share code, notes, and snippets.

@ateleshev
Forked from atotto/chan_test.go
Last active February 26, 2016 13:13
Show Gist options
  • Save ateleshev/b38a461cb9ed26353d87 to your computer and use it in GitHub Desktop.
Save ateleshev/b38a461cb9ed26353d87 to your computer and use it in GitHub Desktop.
golang channel benchmark
package chan_test
import (
"testing"
)
func BenchmarkStructChan(b *testing.B) {
ch := make(chan struct{})
go func() {
for {
<-ch
}
}()
for i := 0; i < b.N; i++ {
ch <- struct{}{}
}
}
func BenchmarkBoolChan(b *testing.B) {
ch := make(chan bool)
go func() {
for {
<-ch
}
}()
for i := 0; i < b.N; i++ {
ch <- true
}
}
func BenchmarkIntChan(b *testing.B) {
ch := make(chan int)
go func() {
for {
<-ch
}
}()
for i := 0; i < b.N; i++ {
ch <- 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment