-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathccss_bench_test.go
100 lines (85 loc) · 2.46 KB
/
ccss_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
package goccss_test
import (
"testing"
goccss "github.com/pandatix/go-ccss"
)
var Gccss *goccss.CCSS
var Gerr error
func BenchmarkParseVector_Base(b *testing.B) {
benchmarkParseVector("AV:L/AC:L/Au:N/C:P/I:P/A:P/PL:U/EM:A", b)
}
func BenchmarkParseVector_WithTempAndEnv(b *testing.B) {
benchmarkParseVector("AV:L/AC:L/Au:N/C:P/I:P/A:P/PL:U/EM:A/GEL:L/GRL:M/LVP:L/PTV:L/LRL:L/EC:C/EI:C/EA:C/CDP:L/CR:M/IR:M/AR:L", b)
}
func benchmarkParseVector(vector string, b *testing.B) {
var ccss *goccss.CCSS
var err error
b.ResetTimer()
for i := 0; i < b.N; i++ {
ccss, err = goccss.ParseVector(vector)
}
Gccss = ccss
Gerr = err
}
var Gstr string
func BenchmarkCCSSVector(b *testing.B) {
ccss, _ := goccss.ParseVector("AV:L/AC:L/Au:N/C:P/I:P/A:P/PL:U/EM:A/GEL:L/GRL:M/LVP:L/PTV:L/LRL:L/EC:C/EI:C/EA:C/CDP:L/CR:M/IR:M/AR:L")
var str string
b.ResetTimer()
for i := 0; i < b.N; i++ {
str = ccss.Vector()
}
Gstr = str
}
var Gget string
func BenchmarkCCSSGet(b *testing.B) {
const abv = "Au"
ccss, _ := goccss.ParseVector("AV:L/AC:L/Au:N/C:P/I:P/A:P/PL:U/EM:A/GEL:L/GRL:M/LVP:L/PTV:L/LRL:L/EC:C/EI:C/EA:C/CDP:L/CR:M/IR:M/AR:L")
var get string
var err error
b.ResetTimer()
for i := 0; i < b.N; i++ {
get, err = ccss.Get(abv)
}
Gget = get
Gerr = err
}
func BenchmarkCCSSSet(b *testing.B) {
const abv = "Au"
const value = "S"
ccss, _ := goccss.ParseVector("AV:L/AC:L/Au:N/C:P/I:P/A:P/PL:U/EM:A/GEL:L/GRL:M/LVP:L/PTV:L/LRL:L/EC:C/EI:C/EA:C/CDP:L/CR:M/IR:M/AR:L")
var err error
b.ResetTimer()
for i := 0; i < b.N; i++ {
err = ccss.Set(abv, value)
}
Gerr = err
}
var Gscore float64
func BenchmarkCCSSBaseScore(b *testing.B) {
var score float64
ccss, _ := goccss.ParseVector("AV:L/AC:L/Au:N/C:P/I:P/A:P/PL:U/EM:A/GEL:L/GRL:M/LVP:L/PTV:L/LRL:L/EC:C/EI:C/EA:C/CDP:L/CR:M/IR:M/AR:L")
b.ResetTimer()
for i := 0; i < b.N; i++ {
score = ccss.BaseScore()
}
Gscore = score
}
func BenchmarkCCSSTemporalScore(b *testing.B) {
var score float64
ccss, _ := goccss.ParseVector("AV:L/AC:L/Au:N/C:P/I:P/A:P/PL:U/EM:A/GEL:L/GRL:M/LVP:L/PTV:L/LRL:L/EC:C/EI:C/EA:C/CDP:L/CR:M/IR:M/AR:L")
b.ResetTimer()
for i := 0; i < b.N; i++ {
score = ccss.TemporalScore()
}
Gscore = score
}
func BenchmarkCCSSEnvironmentalScore(b *testing.B) {
var score float64
ccss, _ := goccss.ParseVector("AV:L/AC:L/Au:N/C:P/I:P/A:P/PL:U/EM:A/GEL:L/GRL:M/LVP:L/PTV:L/LRL:L/EC:C/EI:C/EA:C/CDP:L/CR:M/IR:M/AR:L")
b.ResetTimer()
for i := 0; i < b.N; i++ {
score = ccss.EnvironmentalScore()
}
Gscore = score
}