-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbench_test.go
More file actions
164 lines (138 loc) · 3.2 KB
/
Copy pathbench_test.go
File metadata and controls
164 lines (138 loc) · 3.2 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package vers
import "testing"
// Parsing benchmarks
func BenchmarkParse_VersURI_Simple(b *testing.B) {
for b.Loop() {
_, _ = Parse("vers:npm/>=1.2.3")
}
}
func BenchmarkParse_VersURI_Complex(b *testing.B) {
for b.Loop() {
_, _ = Parse("vers:npm/>=1.2.3|<2.0.0|!=1.5.0")
}
}
func BenchmarkParseNative_Npm_Caret(b *testing.B) {
for b.Loop() {
_, _ = ParseNative("^1.2.3", "npm")
}
}
func BenchmarkParseNative_Npm_Tilde(b *testing.B) {
for b.Loop() {
_, _ = ParseNative("~1.2.3", "npm")
}
}
func BenchmarkParseNative_Npm_Range(b *testing.B) {
for b.Loop() {
_, _ = ParseNative(">=1.0.0 <2.0.0", "npm")
}
}
func BenchmarkParseNative_Npm_Or(b *testing.B) {
for b.Loop() {
_, _ = ParseNative("^1.0.0 || ^2.0.0 || ^3.0.0", "npm")
}
}
func BenchmarkParseNative_Gem_Pessimistic(b *testing.B) {
for b.Loop() {
_, _ = ParseNative("~> 1.2.3", "gem")
}
}
func BenchmarkParseNative_Pypi_Compatible(b *testing.B) {
for b.Loop() {
_, _ = ParseNative("~=1.4.2", "pypi")
}
}
func BenchmarkParseNative_Maven_Bracket(b *testing.B) {
for b.Loop() {
_, _ = ParseNative("[1.0,2.0)", "maven")
}
}
// Contains benchmarks
func BenchmarkContains_Simple(b *testing.B) {
r, _ := ParseNative("^1.2.3", "npm")
b.ResetTimer()
for b.Loop() {
r.Contains("1.5.0")
}
}
func BenchmarkContains_MultiInterval(b *testing.B) {
r, _ := ParseNative("^1.0.0 || ^2.0.0 || ^3.0.0", "npm")
b.ResetTimer()
for b.Loop() {
r.Contains("2.5.0")
}
}
func BenchmarkContains_WithExclusions(b *testing.B) {
r, _ := Parse("vers:npm/>=1.0.0|<2.0.0|!=1.5.0|!=1.6.0|!=1.7.0")
b.ResetTimer()
for b.Loop() {
r.Contains("1.8.0")
}
}
func BenchmarkContains_Prerelease(b *testing.B) {
r, _ := ParseNative(">=1.0.0-alpha.1", "npm")
b.ResetTimer()
for b.Loop() {
r.Contains("1.0.0-beta.2")
}
}
func BenchmarkCompare_Simple(b *testing.B) {
for b.Loop() {
Compare("1.2.3", "1.2.4")
}
}
func BenchmarkCompare_Prerelease(b *testing.B) {
for b.Loop() {
Compare("1.0.0-alpha.1", "1.0.0-beta.2")
}
}
// Range operation benchmarks
func BenchmarkUnion_TwoRanges(b *testing.B) {
r1, _ := ParseNative("^1.0.0", "npm")
r2, _ := ParseNative("^2.0.0", "npm")
b.ResetTimer()
for b.Loop() {
r1.Union(r2)
}
}
func BenchmarkUnion_ManyRanges(b *testing.B) {
ranges := make([]*Range, 10)
for i := range ranges {
ranges[i], _ = ParseNative("^1.0.0", "npm")
}
b.ResetTimer()
for b.Loop() {
result := ranges[0]
for _, r := range ranges[1:] {
result = result.Union(r)
}
}
}
func BenchmarkIntersect_TwoRanges(b *testing.B) {
r1, _ := ParseNative(">=1.0.0", "npm")
r2, _ := ParseNative("<2.0.0", "npm")
b.ResetTimer()
for b.Loop() {
r1.Intersect(r2)
}
}
func BenchmarkIntersect_ManyRanges(b *testing.B) {
r1, _ := ParseNative(">=1.0.0", "npm")
r2, _ := ParseNative("<3.0.0", "npm")
r3, _ := ParseNative(">=1.5.0", "npm")
r4, _ := ParseNative("<2.5.0", "npm")
b.ResetTimer()
for b.Loop() {
r1.Intersect(r2).Intersect(r3).Intersect(r4)
}
}
// Satisfies benchmarks (combines parsing and contains)
func BenchmarkSatisfies_VersURI(b *testing.B) {
for b.Loop() {
_, _ = Satisfies("1.5.0", "vers:npm/>=1.0.0|<2.0.0", "")
}
}
func BenchmarkSatisfies_Native(b *testing.B) {
for b.Loop() {
_, _ = Satisfies("1.5.0", "^1.2.3", "npm")
}
}