-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_test.go
More file actions
81 lines (67 loc) · 2.59 KB
/
benchmark_test.go
File metadata and controls
81 lines (67 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package topic_test
import (
"context"
"strconv"
"testing"
"github.com/ostcar/topic"
)
func benchmarkPublishWithXReceivers(count int, b *testing.B) {
ctx := b.Context()
top := topic.New[string]()
for range count {
// Starts a receiver that listens to the topic until shutdown is called.
go func() {
var id uint64
var values []string
for {
id, values, _ = top.ReceiveSince(ctx, id)
if len(values) == 0 {
return
}
}
}()
}
b.ResetTimer()
for b.Loop() {
top.Publish("value")
}
}
func BenchmarkPublishWithXReceivers1(b *testing.B) { benchmarkPublishWithXReceivers(1, b) }
func BenchmarkPublishWithXReceivers10(b *testing.B) { benchmarkPublishWithXReceivers(10, b) }
func BenchmarkPublishWithXReceivers100(b *testing.B) { benchmarkPublishWithXReceivers(100, b) }
func BenchmarkPublishWithXReceivers1000(b *testing.B) { benchmarkPublishWithXReceivers(1_000, b) }
func BenchmarkPublishWithXReceivers10000(b *testing.B) { benchmarkPublishWithXReceivers(10_000, b) }
func benchmarkRetrieveBigTopic(count int, b *testing.B) {
top := topic.New[string]()
for i := range count {
top.Publish("value" + strconv.Itoa(i))
}
b.ResetTimer()
for b.Loop() {
top.ReceiveSince(b.Context(), 0)
}
}
func BenchmarkRetrieveBigTopic1(b *testing.B) { benchmarkRetrieveBigTopic(1, b) }
func BenchmarkRetrieveBigTopic10(b *testing.B) { benchmarkRetrieveBigTopic(10, b) }
func BenchmarkRetrieveBigTopic100(b *testing.B) { benchmarkRetrieveBigTopic(100, b) }
func BenchmarkRetrieveBigTopic1000(b *testing.B) { benchmarkRetrieveBigTopic(1_000, b) }
func BenchmarkRetrieveBigTopic10000(b *testing.B) { benchmarkRetrieveBigTopic(10_000, b) }
func BenchmarkRetrieveBigTopic100000(b *testing.B) { benchmarkRetrieveBigTopic(100_000, b) }
func benchmarkRetrieveLastBigTopic(count int, b *testing.B) {
top := topic.New[string]()
for i := range count {
top.Publish("value" + strconv.Itoa(i))
}
id := top.LastID()
ctx := context.Background()
b.ResetTimer()
for b.Loop() {
top.ReceiveSince(ctx, id-1)
}
}
func BenchmarkRetrieveLastBigTopic1(b *testing.B) { benchmarkRetrieveLastBigTopic(1, b) }
func BenchmarkRetrieveLastBigTopic10(b *testing.B) { benchmarkRetrieveLastBigTopic(10, b) }
func BenchmarkRetrieveLastBigTopic100(b *testing.B) { benchmarkRetrieveLastBigTopic(100, b) }
func BenchmarkRetrieveLastBigTopic1000(b *testing.B) { benchmarkRetrieveLastBigTopic(1_000, b) }
func BenchmarkRetrieveLastBigTopic10000(b *testing.B) { benchmarkRetrieveLastBigTopic(10_000, b) }
func BenchmarkRetrieveLastBigTopic100000(b *testing.B) { benchmarkRetrieveLastBigTopic(100_000, b) }