Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ func main() {
}
```

## Benchmarks

```bash
go test -bench=. -benchmem
```

```
goos: darwin
goarch: arm64
pkg: github.com/floatdrop/ringchan
cpu: Apple M1 Pro
BenchmarkSingleSender-10 7097070 167.3 ns/op 0 B/op 0 allocs/op
BenchmarkParallelSenders-10 4145682 295.0 ns/op 0 B/op 0 allocs/op
PASS
coverage: 90.9% of statements
ok github.com/floatdrop/ringchan 3.050s
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
30 changes: 30 additions & 0 deletions ringchan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,33 @@ func TestRingChanRangeAfterClose(t *testing.T) {
t.Errorf("unexpected results: %v", results)
}
}

func BenchmarkSingleSender(b *testing.B) {
input := make(chan int)
ring := New(input, 1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
input <- i
}
close(input)
for range ring.C {
}
b.StopTimer()
}

func BenchmarkParallelSenders(b *testing.B) {
input := make(chan int)
ring := New(input, 1)
b.ResetTimer()

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
input <- 1
}
})

close(input)
for range ring.C {
}
b.StopTimer()
}
Loading