-
-
Save ateleshev/b38a461cb9ed26353d87 to your computer and use it in GitHub Desktop.
golang channel benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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