-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
benchmark_test.go
76 lines (69 loc) · 1.59 KB
/
benchmark_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
package runn
import (
"context"
"strings"
"testing"
"github.com/k1LoW/runn/testutil"
)
// BenchmarkSingleRunbook is a benchmark of a single runbook.
func BenchmarkSingleRunbook(b *testing.B) {
const (
bookCount = 1
stepCount = 100
bodySize = 1000
)
runBenchmark(b, bookCount, stepCount, bodySize)
}
// BenchmarkManyRunbooks is a benchmark of many runbooks.
func BenchmarkManyRunbooks(b *testing.B) {
const (
bookCount = 1000
stepCount = 10
bodySize = 100
)
runBenchmark(b, bookCount, stepCount, bodySize)
}
// BenchmarkOpenAPI3 is a benchmark with OpenAPI.
func BenchmarkOpenAPI3(b *testing.B) {
const (
bookCount = 10
stepCount = 10
)
runBenchmarkWithOpenAPI3(b, bookCount, stepCount)
}
func runBenchmark(b *testing.B, bookCount, stepCount, bodySize int) {
ctx := context.Background()
body := "data: " + strings.Repeat("a", bodySize)
ts, pathp := testutil.BenchmarkSet(b, bookCount, stepCount, body)
b.ResetTimer()
for i := 0; i < b.N; i++ {
opts := []Option{
HTTPRunner("req", ts.URL, ts.Client()),
Scopes(ScopeAllowReadParent),
}
o, err := Load(pathp, opts...)
if err != nil {
b.Fatal(err)
}
if err := o.RunN(ctx); err != nil {
b.Error(err)
}
}
}
func runBenchmarkWithOpenAPI3(b *testing.B, bookCount, stepCount int) {
ctx := context.Background()
_, pathp := testutil.BenchmarkSetWithOpenAPI3(b, bookCount, stepCount)
b.ResetTimer()
for i := 0; i < b.N; i++ {
opts := []Option{
Scopes(ScopeAllowReadParent),
}
o, err := Load(pathp, opts...)
if err != nil {
b.Fatal(err)
}
if err := o.RunN(ctx); err != nil {
b.Error(err)
}
}
}