-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_test.go
60 lines (52 loc) · 1.15 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
// Copyright (c) 2021-2023 James Bowes. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package semver_test
import (
"testing"
"github.com/jbowes/semver"
)
// Benchmarks are defined as slices so they run in the same order every time,
// for easier visual comparison.
func BenchmarkParse(b *testing.B) {
bcs := []struct {
name string
in string
}{
{"simple", "1.2.3"},
{"pre", "1.2.3-beta"},
{"build", "1.2.3+build"},
{"pre+build", "1.2.3-rc.1+build.info"},
}
for _, bc := range bcs {
b.Run(bc.name, func(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = semver.Parse(bc.in)
}
})
}
}
func BenchmarkParseConstraint(b *testing.B) {
bcs := []struct {
name string
in string
}{
{"equal", "=2.2"},
{"tilde", "~2.2.0"},
{"caret", "^2.2.0"},
{"wildcard", "1.x"},
{"range", ">=2.2.x <3.2.0"},
{"union", "~2.2.0 || =3.3.0"},
}
for _, bc := range bcs {
b.Run(bc.name, func(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = semver.ParseConstraint(bc.in)
}
})
}
}