-
Notifications
You must be signed in to change notification settings - Fork 4
/
scenario_v3_bench_test.go
183 lines (176 loc) · 4.35 KB
/
scenario_v3_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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package benchmarks
import (
"testing"
bunji2 "github.com/bunji2/cvssv3"
facebook3 "github.com/facebookincubator/nvdtools/cvss3"
goark3 "github.com/goark/go-cvss/v3/metric"
pandatix31 "github.com/pandatix/go-cvss/31"
)
const (
cvss31vector = "CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:N/A:L"
)
// This benchmarks the parsing function on a CVSS v3.1 vector.
// The vector contains only Base metrics as it is the most common
// case in the NVD.
func Benchmark_V3_ParseVector(b *testing.B) {
b.Run("pandatix/go-cvss", func(b *testing.B) {
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var vec *pandatix31.CVSS31
var err error
for pb.Next() {
vec, err = pandatix31.ParseVector(cvss31vector)
}
GpandatixVec3 = vec
Gerr = err
})
})
// umisama/go-cvss can't handle CVSS v3
b.Run("bunji2/cvssv3", func(b *testing.B) {
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var vec bunji2.Vector
var err error
for pb.Next() {
vec, err = bunji2.ParseVector(cvss31vector)
}
Gbunji2Vec = vec
Gerr = err
})
})
b.Run("goark/go-cvss", func(b *testing.B) {
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var vec = goark3.NewBase()
var err error
for pb.Next() {
_, err = vec.Decode(cvss31vector)
}
GgoarkVec3 = vec
Gerr = err
})
})
b.Run("facebookincubator/nvdtools", func(b *testing.B) {
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var vec facebook3.Vector
var err error
for pb.Next() {
vec, err = facebook3.VectorFromString(cvss31vector)
}
GfacebookVec3 = vec
Gerr = err
})
})
// slimsec/cvss can't handle CVSS v3 parsing
// zntrio/mitre can't handle CVSS v3 parsing
}
// This benchmarks the vectorizing function on a CVSS v3.1 vector.
// The returned vector contains only Base metrics as it is the most
// common case in the NVD.
func Benchmark_V3_Vector(b *testing.B) {
b.Run("pandatix/go-cvss", func(b *testing.B) {
vec, _ := pandatix31.ParseVector(cvss31vector)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var str string
for pb.Next() {
str = vec.Vector()
}
Gstr = str
})
})
// umisama/go-cvss can't handle CVSS v3
b.Run("bunji2/cvssv3", func(b *testing.B) {
vec, _ := bunji2.ParseVector(cvss31vector)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var str string
for pb.Next() {
str = vec.String()
}
Gstr = str
})
})
b.Run("goark/go-cvss", func(b *testing.B) {
vec, _ := goark3.NewBase().Decode(cvss31vector)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var str string
for pb.Next() {
str, _ = vec.Encode()
}
Gstr = str
})
})
b.Run("facebookincubator/nvdtools", func(b *testing.B) {
vec, _ := facebook3.VectorFromString(cvss31vector)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var str string
for pb.Next() {
str = vec.String()
}
Gstr = str
})
})
// slimsec/cvss can't handle CVSS v3 vectorizing
// zntrio/mitre can't handle CVSS v3 vectorizing due to unhandled parsing
}
// This benchmarks the base score computing on a CVSS v3.1 vector.
// Only the base score is computed
func Benchmark_V3_BaseScore(b *testing.B) {
b.Run("pandatix/go-cvss", func(b *testing.B) {
vec, _ := pandatix31.ParseVector(cvss31vector)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var f float64
for pb.Next() {
f = vec.BaseScore()
}
Gf = f
})
})
// umisama/go-cvss can't handle CVSS v3
b.Run("bunji2/cvssv3", func(b *testing.B) {
vec, _ := bunji2.ParseVector(cvss31vector)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var f float64
for pb.Next() {
f = vec.BaseScore()
}
Gf = f
})
})
b.Run("goark/go-cvss", func(b *testing.B) {
vec, _ := goark3.NewBase().Decode(cvss31vector)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var f float64
for pb.Next() {
f = vec.Score()
}
Gf = f
})
})
b.Run("facebookincubator/nvdtools", func(b *testing.B) {
vec, _ := facebook3.VectorFromString(cvss31vector)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var f float64
for pb.Next() {
f = vec.BaseScore()
}
Gf = f
})
})
// slimsec/cvss can't handle CVSS v3 base score computing
// zntrio/mitre can't handle CVSS v3 base score computing due to unhandled parsing
}
var (
GpandatixVec3 *pandatix31.CVSS31
Gbunji2Vec bunji2.Vector
GgoarkVec3 *goark3.Base
GfacebookVec3 facebook3.Vector
)