forked from mission-liao/dingo
/
bench_test.go
86 lines (74 loc) · 1.31 KB
/
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package dingo_test
import (
"testing"
"github.com/mission-liao/dingo"
)
var testWork = func(count int, msg string) (string, int) {
return msg, count
}
func BenchmarkRaw(b *testing.B) {
var (
count = 1
msg = "test string"
)
for i := 0; i < b.N; i++ {
msg, count = testWork(count, msg)
}
}
func BenchmarkLocal(b *testing.B) {
var (
err error
count = 1
msg = "test string"
)
defer func() {
if err != nil {
b.Fatalf("failed: %v\n", err)
}
}()
app, err := dingo.NewApp("local", nil)
if err != nil {
return
}
err = app.Register("myWork", testWork)
if err != nil {
return
}
_, err = app.Allocate("myWork", 10, 3)
if err != nil {
return
}
// setup for invoker
err = app.AddMarshaller(101, &struct {
dingo.GobMarshaller
testMyInvoker
}{
dingo.GobMarshaller{},
testMyInvoker{},
})
if err != nil {
return
}
err = app.SetMarshaller("myWork", 101, 101)
if err != nil {
return
}
// setup for idmaker
err = app.AddIDMaker(101, &dingo.SeqIDMaker{})
if err != nil {
return
}
err = app.SetIDMaker("myWork", 101)
if err != nil {
return
}
// reset timer for preparation
b.ResetTimer()
var result *dingo.Result
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
result = dingo.NewResult(app.Call("myWork", nil, count, msg))
result.Wait(0)
}
})
}