aboutsummaryrefslogtreecommitdiff
path: root/pipeline/pipeline_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 /pipeline/pipeline_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 'pipeline/pipeline_bench_test.go')
-rw-r--r--pipeline/pipeline_bench_test.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/pipeline/pipeline_bench_test.go b/pipeline/pipeline_bench_test.go
new file mode 100644
index 0000000..f4f81a0
--- /dev/null
+++ b/pipeline/pipeline_bench_test.go
@@ -0,0 +1,55 @@
1package pipeline
2
3import (
4 "context"
5 "testing"
6)
7
8func BenchmarkMap(b *testing.B) {
9 b.ReportAllocs()
10
11 input := make(chan int, 256)
12
13 out := Run(b.Context(), input,
14 Map(4, func(_ context.Context, v int) (int, bool) {
15 return v * 2, true
16 }),
17 )
18
19 go func() {
20 for range out {
21 }
22 }()
23
24 for b.Loop() {
25 input <- 1
26 }
27
28 close(input)
29}
30
31func BenchmarkPipeline_Composition(b *testing.B) {
32 b.ReportAllocs()
33
34 input := make(chan int, 256)
35
36 out := Run(b.Context(), input,
37 Filter(func(v int) bool { return v > 0 }),
38 Map(4, func(_ context.Context, v int) (int, bool) {
39 return v * 2, true
40 }),
41 Buffer[int](64),
42 Sink(2, func(_ context.Context, v int) {}),
43 )
44
45 go func() {
46 for range out {
47 }
48 }()
49
50 for b.Loop() {
51 input <- 1
52 }
53
54 close(input)
55}