This repository has been archived by the owner on Nov 17, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
bench_test.go
101 lines (86 loc) · 2.42 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package gherkin
import (
messages "github.com/cucumber/common/messages/go/v19"
"strings"
"testing"
)
const benchmarkGherkinText = `
@dead @simple
Feature: Dead Simple Calculator
Bla Bla
Bla
Background:
Given a Simple Calculator
@wip
Scenario: Adding 2 numbers
When I press the key "2"
And I press the key "+"
And I press the key "2"
And I press the key "="
Then the result should be 4
@wip @expensive
Scenario Outline: Simple Math
When I press the key "<left>"
And I press the key "<operator>"
And I press the key "<right>"
And I press the key "="
Then the result should be "<result>"
Examples:
| left | operator | right | result |
| 2 | + | 2 | 4 |
| 3 | + | 4 | 7 |
Scenario: Adding 3 numbers
When I press the following keys:
"""
2
+ 2
+ 5
=
"""
Then the result should be 9
`
func Benchmark_NewParserMatcherScanner(b *testing.B) { //benchmark function starts with "Benchmark" and takes a pointer to type testing.B
for i := 0; i < b.N; i++ { // use b.N for looping
noopbuilder := new(noopBuilder)
_ = NewParser(noopbuilder)
_ = NewMatcher(DialectsBuiltin())
_ = NewScanner(strings.NewReader(benchmarkGherkinText))
}
}
func Benchmark_ParseGherkinDocument(b *testing.B) { //benchmark function starts with "Benchmark" and takes a pointer to type testing.B
for i := 0; i < b.N; i++ { // use b.N for looping
r := strings.NewReader(benchmarkGherkinText)
_, err := ParseGherkinDocument(r, (&messages.Incrementing{}).NewId)
if err != nil {
b.FailNow()
}
}
}
type noopBuilder struct{}
func (n *noopBuilder) Build(*Token) (bool, error) {
return true, nil
}
func (n *noopBuilder) StartRule(RuleType) (bool, error) {
return true, nil
}
func (n *noopBuilder) EndRule(RuleType) (bool, error) {
return true, nil
}
func (n *noopBuilder) Reset() {
}
func Benchmark_ParseWithoutBuilder(b *testing.B) { //benchmark function starts with "Benchmark" and takes a pointer to type testing.B
b.StopTimer()
noopbuilder := new(noopBuilder)
parser := NewParser(noopbuilder)
parser.StopAtFirstError(true)
matcher := NewMatcher(DialectsBuiltin())
b.StartTimer()
for i := 0; i < b.N; i++ { // use b.N for looping
in := strings.NewReader(benchmarkGherkinText)
scanner := NewScanner(in)
err := parser.Parse(scanner, matcher)
if err != nil {
b.FailNow()
}
}
}