aboutsummaryrefslogtreecommitdiff
path: root/fanin/fanin_bench_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'fanin/fanin_bench_test.go')
-rw-r--r--fanin/fanin_bench_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/fanin/fanin_bench_test.go b/fanin/fanin_bench_test.go
new file mode 100644
index 0000000..1141224
--- /dev/null
+++ b/fanin/fanin_bench_test.go
@@ -0,0 +1,36 @@
1package fanin
2
3import (
4 "testing"
5)
6
7func BenchmarkFanIn(b *testing.B) {
8 b.ReportAllocs()
9
10 fi, _ := NewFanIn[int](WithBufferSize(64))
11
12 producers := 4
13 chs := make([]chan int, producers)
14 for i := range chs {
15 chs[i] = make(chan int, 64)
16 fi.Add(chs[i])
17 }
18
19 out := fi.Run(b.Context())
20
21 // Drain output
22 go func() {
23 for range out {
24 }
25 }()
26
27 for b.Loop() {
28 chs[b.N%producers] <- 1
29 }
30
31 for _, ch := range chs {
32 close(ch)
33 }
34
35 <-fi.Done()
36}