-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpubsub_bench_test.go
62 lines (48 loc) · 998 Bytes
/
pubsub_bench_test.go
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
package haro
import (
"context"
"testing"
)
func BenchmarkPublish_int(b *testing.B) {
t := DeclareTopic[int]()
outputChan := make(chan int, b.N)
t.Subscribe(func(ctx context.Context, p int) error {
outputChan <- p
return nil
})
for i := 0; i < b.N; i++ {
_ = t.Publish(context.Background(), 5)
<-outputChan
}
}
func BenchmarkPublish_string(b *testing.B) {
t := DeclareTopic[string]()
outputChan := make(chan string, b.N)
t.Subscribe(func(ctx context.Context, p string) error {
outputChan <- p
return nil
})
for i := 0; i < b.N; i++ {
_ = t.Publish(context.Background(), "test")
<-outputChan
}
}
func BenchmarkPublish_struct(b *testing.B) {
type d struct {
id int64
name string
}
t := DeclareTopic[d]()
outputChan := make(chan d, b.N)
t.Subscribe(func(ctx context.Context, p d) error {
outputChan <- p
return nil
})
for i := 0; i < b.N; i++ {
_ = t.Publish(context.Background(), d{
id: 1,
name: "test",
})
<-outputChan
}
}