File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -57,6 +57,24 @@ func main() {
5757}
5858```
5959
60+ ## Benchmarks
61+
62+ ``` bash
63+ go test -bench=. -benchmem
64+ ```
65+
66+ ```
67+ goos: darwin
68+ goarch: arm64
69+ pkg: github.com/floatdrop/ringchan
70+ cpu: Apple M1 Pro
71+ BenchmarkSingleSender-10 7097070 167.3 ns/op 0 B/op 0 allocs/op
72+ BenchmarkParallelSenders-10 4145682 295.0 ns/op 0 B/op 0 allocs/op
73+ PASS
74+ coverage: 90.9% of statements
75+ ok github.com/floatdrop/ringchan 3.050s
76+ ```
77+
6078## License
6179
6280This project is licensed under the MIT License - see the [ LICENSE] ( LICENSE ) file for details.
Original file line number Diff line number Diff line change @@ -76,3 +76,33 @@ func TestRingChanRangeAfterClose(t *testing.T) {
7676 t .Errorf ("unexpected results: %v" , results )
7777 }
7878}
79+
80+ func BenchmarkSingleSender (b * testing.B ) {
81+ input := make (chan int )
82+ ring := New (input , 1 )
83+ b .ResetTimer ()
84+ for i := 0 ; i < b .N ; i ++ {
85+ input <- i
86+ }
87+ close (input )
88+ for range ring .C {
89+ }
90+ b .StopTimer ()
91+ }
92+
93+ func BenchmarkParallelSenders (b * testing.B ) {
94+ input := make (chan int )
95+ ring := New (input , 1 )
96+ b .ResetTimer ()
97+
98+ b .RunParallel (func (pb * testing.PB ) {
99+ for pb .Next () {
100+ input <- 1
101+ }
102+ })
103+
104+ close (input )
105+ for range ring .C {
106+ }
107+ b .StopTimer ()
108+ }
You can’t perform that action at this time.
0 commit comments