Skip to content

Commit 5a51745

Browse files
committed
chore(benchmark): add performance benchmark.
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
1 parent cb8720b commit 5a51745

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

.github/workflows/go.yml

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ jobs:
5858
- name: Run Tests
5959
run: |
6060
go test -v -covermode=atomic -coverprofile=coverage.out
61+
62+
- name: Run Benchmark
63+
run: |
6164
go test -v -run=^$ -benchmem -bench .
6265
6366
- name: Upload coverage to Codecov

benchmark_test.go

+50
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ package queue
33
import (
44
"context"
55
"testing"
6+
"time"
7+
8+
"github.com/golang-queue/queue/core"
9+
"github.com/golang-queue/queue/job"
610
)
711

812
func BenchmarkQueueTask(b *testing.B) {
@@ -27,3 +31,49 @@ func BenchmarkQueue(b *testing.B) {
2731
_ = q.Queue(m)
2832
}
2933
}
34+
35+
func BenchmarkConsumerPayload(b *testing.B) {
36+
b.ReportAllocs()
37+
38+
task := &job.Message{
39+
Timeout: 100 * time.Millisecond,
40+
Payload: []byte(`{"timeout":3600000000000}`),
41+
}
42+
w := NewConsumer(
43+
WithFn(func(ctx context.Context, m core.QueuedMessage) error {
44+
return nil
45+
}),
46+
)
47+
48+
q, _ := NewQueue(
49+
WithWorker(w),
50+
)
51+
52+
for n := 0; n < b.N; n++ {
53+
_ = q.run(task)
54+
}
55+
}
56+
57+
func BenchmarkConsumerTask(b *testing.B) {
58+
b.ReportAllocs()
59+
60+
task := &job.Message{
61+
Timeout: 100 * time.Millisecond,
62+
Task: func(_ context.Context) error {
63+
return nil
64+
},
65+
}
66+
w := NewConsumer(
67+
WithFn(func(ctx context.Context, m core.QueuedMessage) error {
68+
return nil
69+
}),
70+
)
71+
72+
q, _ := NewQueue(
73+
WithWorker(w),
74+
)
75+
76+
for n := 0; n < b.N; n++ {
77+
_ = q.run(task)
78+
}
79+
}

0 commit comments

Comments
 (0)