From 02123df8cc15896f97c1580e49d8e2a991e37ddd Mon Sep 17 00:00:00 2001 From: sangtran Date: Thu, 3 Sep 2026 23:10:33 +0700 Subject: Moving all legacy quacker source code from github to cgit --- fanout/fanout_bench_test.go | 65 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 fanout/fanout_bench_test.go (limited to 'fanout/fanout_bench_test.go') 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 @@ +package fanout + +import ( + "context" + "testing" +) + +func BenchmarkFanOut_RoundRobin(b *testing.B) { + b.ReportAllocs() + + fo, _ := NewFanOut[int]( + WithWorkerCount(4), + WithBufferSize(64), + WithStrategy(RoundRobin), + ) + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + input := make(chan int, 64) + fo.Run(ctx, input) + + // Drain outputs + for _, ch := range fo.Outputs() { + go func() { + for range ch { + } + }() + } + + for b.Loop() { + input <- 1 + } + + close(input) +} + +func BenchmarkFanOut_Broadcast(b *testing.B) { + b.ReportAllocs() + + fo, _ := NewFanOut[int]( + WithWorkerCount(4), + WithBufferSize(64), + WithStrategy(Broadcast), + ) + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + input := make(chan int, 64) + fo.Run(ctx, input) + + for _, ch := range fo.Outputs() { + go func() { + for range ch { + } + }() + } + + for b.Loop() { + input <- 1 + } + + close(input) +} -- cgit v1.3.1