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 --- workerpool/workerpool_bench_test.go | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 workerpool/workerpool_bench_test.go (limited to 'workerpool/workerpool_bench_test.go') 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 @@ +package workerpool + +import ( + "context" + "fmt" + "testing" +) + +type benchTask struct { + id string +} + +func (t *benchTask) Execute(_ context.Context) error { return nil } +func (t *benchTask) GetID() string { return t.id } + +func BenchmarkWorkerPool(b *testing.B) { + b.ReportAllocs() + + pool, _ := NewWorkerPool[*benchTask](b.Context(), + WithNumWorkers(4), + WithTaskQueueSize(256), + ) + pool.Start() + + task := &benchTask{id: "bench"} + + for b.Loop() { + pool.Push(task) + } + + pool.StopAndWait() +} + +func BenchmarkWorkerPool_Push(b *testing.B) { + b.ReportAllocs() + + pool, _ := NewWorkerPool[*benchTask](b.Context(), + WithNumWorkers(8), + WithTaskQueueSize(1024), + ) + pool.Start() + defer pool.StopAndWait() + + b.RunParallel(func(pb *testing.PB) { + task := &benchTask{id: fmt.Sprintf("bench-%d", b.N)} + for pb.Next() { + pool.Push(task) + } + }) +} -- cgit v1.3.1