aboutsummaryrefslogtreecommitdiff
path: root/fanout/fanout_bench_test.go
diff options
context:
space:
mode:
authorsangtran <tranquangsang12.7@gmail.com>2026-09-03 23:10:33 +0700
committersangtran <tranquangsang12.7@gmail.com>2026-09-03 23:10:33 +0700
commit02123df8cc15896f97c1580e49d8e2a991e37ddd (patch)
treed0c00bc3f65e5f5493a9dff8034c80640cb12960 /fanout/fanout_bench_test.go
signatureVerified sangtran <tranquangsang12.7@gmail.com> Key: 8DD79823D235E1BB ultimate trust
downloadquacker-main.tar.gz
quacker-main.zip
Verified Moving all legacy quacker source code from github to cgitHEADmain
Diffstat (limited to 'fanout/fanout_bench_test.go')
-rw-r--r--fanout/fanout_bench_test.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/fanout/fanout_bench_test.go b/fanout/fanout_bench_test.go
new file mode 100644
index 0000000..0b88d87
--- /dev/null
+++ b/fanout/fanout_bench_test.go
@@ -0,0 +1,65 @@
1package fanout
2
3import (
4 "context"
5 "testing"
6)
7
8func BenchmarkFanOut_RoundRobin(b *testing.B) {
9 b.ReportAllocs()
10
11 fo, _ := NewFanOut[int](
12 WithWorkerCount(4),
13 WithBufferSize(64),
14 WithStrategy(RoundRobin),
15 )
16
17 ctx, cancel := context.WithCancel(context.Background())
18 defer cancel()
19
20 input := make(chan int, 64)
21 fo.Run(ctx, input)
22
23 // Drain outputs
24 for _, ch := range fo.Outputs() {
25 go func() {
26 for range ch {
27 }
28 }()
29 }
30
31 for b.Loop() {
32 input <- 1
33 }
34
35 close(input)
36}
37
38func BenchmarkFanOut_Broadcast(b *testing.B) {
39 b.ReportAllocs()
40
41 fo, _ := NewFanOut[int](
42 WithWorkerCount(4),
43 WithBufferSize(64),
44 WithStrategy(Broadcast),
45 )
46
47 ctx, cancel := context.WithCancel(context.Background())
48 defer cancel()
49
50 input := make(chan int, 64)
51 fo.Run(ctx, input)
52
53 for _, ch := range fo.Outputs() {
54 go func() {
55 for range ch {
56 }
57 }()
58 }
59
60 for b.Loop() {
61 input <- 1
62 }
63
64 close(input)
65}