Created
December 30, 2019 15:19
-
-
Save calebdoxsey/61967cea2bfa2047ef05d15f5b3a7ba5 to your computer and use it in GitHub Desktop.
channel benchmark
This file contains hidden or 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 main | |
import "testing" | |
func BenchmarkOneByteChannel(b *testing.B) { | |
ch := make(chan [1]byte) | |
go func() { | |
for { | |
<-ch | |
} | |
}() | |
for i := 0; i < b.N; i++ { | |
ch <- [1]byte{} | |
} | |
} | |
func BenchmarkTenByteChannel(b *testing.B) { | |
ch := make(chan [10]byte) | |
go func() { | |
for { | |
<-ch | |
} | |
}() | |
for i := 0; i < b.N; i++ { | |
ch <- [10]byte{} | |
} | |
} | |
func BenchmarkHundredByteChannel(b *testing.B) { | |
ch := make(chan [100]byte) | |
go func() { | |
for { | |
<-ch | |
} | |
}() | |
for i := 0; i < b.N; i++ { | |
ch <- [100]byte{} | |
} | |
} | |
func BenchmarkThousandByteChannel(b *testing.B) { | |
ch := make(chan [1000]byte) | |
go func() { | |
for { | |
<-ch | |
} | |
}() | |
for i := 0; i < b.N; i++ { | |
ch <- [1000]byte{} | |
} | |
} |
Author
calebdoxsey
commented
Dec 30, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment