You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
backend: improve parse function performance in gtime package (#1238)
* have unit tests for parse function
* define benchmark test for parse function
* add one more test casae
* Improve the code
* fast return when the input is empty
Copy file name to clipboardexpand all lines: backend/gtime/gtime_bench_test.go
+25
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,30 @@ import (
4
4
"testing"
5
5
)
6
6
7
+
// go test -benchmem -run=^$ -bench=BenchmarkParse$ github.com/grafana/grafana-plugin-sdk-go/backend/gtime/ -memprofile p_mem.out -count 6 | tee pmem.0.txt
8
+
funcBenchmarkParse(b*testing.B) {
9
+
testCases:= []struct {
10
+
namestring
11
+
inputstring
12
+
}{
13
+
{"PureNumber", "30"},
14
+
{"SimpleUnit", "5s"},
15
+
{"ComplexUnit", "1h30m"},
16
+
{"DateUnit", "7d"},
17
+
{"MonthUnit", "3M"},
18
+
{"YearUnit", "1y"},
19
+
}
20
+
21
+
for_, tc:=rangetestCases {
22
+
b.Run(tc.name, func(b*testing.B) {
23
+
b.ResetTimer()
24
+
fori:=0; i<b.N; i++ {
25
+
_, _, _=parse(tc.input)
26
+
}
27
+
})
28
+
}
29
+
}
30
+
7
31
// go test -benchmem -run=^$ -bench=BenchmarkParseIntervalStringToTimeDuration$ github.
8
32
// com/grafana/grafana-plugin-sdk-go/backend/gtime/ -memprofile p_mem.out -count 6 | tee p_mem.txt
0 commit comments