aboutsummaryrefslogtreecommitdiff
path: root/workerpool/workerpool_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 /workerpool/workerpool_bench_test.go
signatureVerified sangtran <tranquangsang12.7@gmail.com> Key: 8DD79823D235E1BB ultimate trust
downloadquacker-02123df8cc15896f97c1580e49d8e2a991e37ddd.tar.gz
quacker-02123df8cc15896f97c1580e49d8e2a991e37ddd.zip
Verified Moving all legacy quacker source code from github to cgitHEADmain
Diffstat (limited to 'workerpool/workerpool_bench_test.go')
-rw-r--r--workerpool/workerpool_bench_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/workerpool/workerpool_bench_test.go b/workerpool/workerpool_bench_test.go
new file mode 100644
index 0000000..1fbc672
--- /dev/null
+++ b/workerpool/workerpool_bench_test.go
@@ -0,0 +1,50 @@
1package workerpool
2
3import (
4 "context"
5 "fmt"
6 "testing"
7)
8
9type benchTask struct {
10 id string
11}
12
13func (t *benchTask) Execute(_ context.Context) error { return nil }
14func (t *benchTask) GetID() string { return t.id }
15
16func BenchmarkWorkerPool(b *testing.B) {
17 b.ReportAllocs()
18
19 pool, _ := NewWorkerPool[*benchTask](b.Context(),
20 WithNumWorkers(4),
21 WithTaskQueueSize(256),
22 )
23 pool.Start()
24
25 task := &benchTask{id: "bench"}
26
27 for b.Loop() {
28 pool.Push(task)
29 }
30
31 pool.StopAndWait()
32}
33
34func BenchmarkWorkerPool_Push(b *testing.B) {
35 b.ReportAllocs()
36
37 pool, _ := NewWorkerPool[*benchTask](b.Context(),
38 WithNumWorkers(8),
39 WithTaskQueueSize(1024),
40 )
41 pool.Start()
42 defer pool.StopAndWait()
43
44 b.RunParallel(func(pb *testing.PB) {
45 task := &benchTask{id: fmt.Sprintf("bench-%d", b.N)}
46 for pb.Next() {
47 pool.Push(task)
48 }
49 })
50}