-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscenario_v4_bench_test.go
66 lines (59 loc) · 1.48 KB
/
scenario_v4_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
package benchmarks
import (
"testing"
pandatix40 "github.com/pandatix/go-cvss/40"
)
const (
cvss40vector = "CVSS:4.0/AV:N/AC:L/AT:N/PR:H/UI:N/VC:L/VI:L/VA:N/SC:N/SI:N/SA:N"
)
// This benchmarks the parsing function on a CVSS v4.0 vector.
// The vector contains only Base metrics as it is the most common
// case in the NVD.
func Benchmark_V4_ParseVector(b *testing.B) {
b.Run("pandatix/go-cvss", func(b *testing.B) {
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var vec *pandatix40.CVSS40
var err error
for pb.Next() {
vec, err = pandatix40.ParseVector(cvss40vector)
}
GpandatixVec4 = vec
Gerr = err
})
})
}
// This benchmarks the vectorizing function on a CVSS v4.0 vector.
// The returned vector contains only Base metrics as it is the most
// common case in the NVD.
func Benchmark_V4_Vector(b *testing.B) {
b.Run("pandatix/go-cvss", func(b *testing.B) {
vec, _ := pandatix40.ParseVector(cvss40vector)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var str string
for pb.Next() {
str = vec.Vector()
}
Gstr = str
})
})
}
// This benchmarks the score computing on a CVSS v4.0 vector.
// Only the base score is computed.
func Benchmark_V4_BaseScore(b *testing.B) {
b.Run("pandatix/go-cvss", func(b *testing.B) {
vec, _ := pandatix40.ParseVector(cvss40vector)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var f float64
for pb.Next() {
f = vec.Score()
}
Gf = f
})
})
}
var (
GpandatixVec4 *pandatix40.CVSS40
)