blob: 1141224b72e03e7eddbd3d8d623342e5f1047a3c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package fanin
import (
"testing"
)
func BenchmarkFanIn(b *testing.B) {
b.ReportAllocs()
fi, _ := NewFanIn[int](WithBufferSize(64))
producers := 4
chs := make([]chan int, producers)
for i := range chs {
chs[i] = make(chan int, 64)
fi.Add(chs[i])
}
out := fi.Run(b.Context())
// Drain output
go func() {
for range out {
}
}()
for b.Loop() {
chs[b.N%producers] <- 1
}
for _, ch := range chs {
close(ch)
}
<-fi.Done()
}
|