-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper_test.go
134 lines (113 loc) · 2.61 KB
/
helper_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
package main
import (
"fmt"
"math"
"strconv"
"testing"
)
///////////////////
// Float64ToString
///////////////////
func BenchmarkFloat64ToString_fmtSprintf(b *testing.B) {
var i float64
for i = 0; i < float64(b.N); i++ {
val := fmt.Sprintf("%f", i)
_ = val
}
}
func BenchmarkFloat64ToString_strconvFormatFloat(b *testing.B) {
var i float64
for i = 0; i < float64(b.N); i++ {
val := strconv.FormatFloat(i, 'g', -1, 64)
_ = val
}
}
///////////////////
// Float32ToString
///////////////////
func BenchmarkFloat32ToString_fmtSprintf(b *testing.B) {
var i float32
for i = 0; i < float32(b.N); i++ {
val := fmt.Sprintf("%f", i)
_ = val
}
}
func BenchmarkFloat32ToString_strconvFormatFloat(b *testing.B) {
var i float64
for i = 0; i < float64(b.N); i++ {
val := strconv.FormatFloat(float64(i), 'g', -1, 32)
_ = val
}
}
///////////////////
// IntToString
///////////////////
func BenchmarkIntToString_strconvItoa(b *testing.B) {
for i := 0; i < b.N; i++ {
val := strconv.Itoa(i)
_ = val
}
}
func BenchmarkIntToString_FormatInt(b *testing.B) {
for i := 0; i < b.N; i++ {
val := strconv.FormatInt(int64(i), 10)
_ = val
}
}
///////////////////
// Float64Round
///////////////////
func BenchmarkFloat64Round_mathRound(b *testing.B) {
var i float64
for i = 0; i < float64(b.N); i++ {
val := math.Round(i*100) / 100
_ = val
}
}
func BenchmarkFloat64Round_fmtSprintf(b *testing.B) {
var i float64
for i = 0; i < float64(b.N); i++ {
val := fmt.Sprintf("%.2f", i)
_ = val
}
}
///////////////////
// Float32Round
///////////////////
// func BenchmarkFloat32Round_mathRound(b *testing.B) {
// var i float32
// for i = 0; i < float32(b.N); i++ {
// val := math.Round(float64(i*100)) / 100
// _ = val
// }
// }
func BenchmarkFloat32Round_fmtSprintf(b *testing.B) {
var i float32
for i = 0; i < float32(b.N); i++ {
val := fmt.Sprintf("%.2f", i)
_ = val
}
}
// func BenchmarkFloat32Round_intFloat(b *testing.B) {
// var i float32
// for i = 0; i < float32(b.N); i++ {
// val := float32(int(i*100)) / 100
// _ = val
// }
// }
///////////////////
// StringsConcat
///////////////////
// fmt.Sprintf("<P=%d,%d><C=FFFFFF><B=%d,%d><C><P=0,0>", c.OSDX, c.OSDY, c.OSDWidth, c.OSDHeight)
func BenchmarkStringsConcat_fmtSprintf(b *testing.B) {
for i := 0; i < b.N; i++ {
val := fmt.Sprintf("<P=%d,%d><C=FFFFFF><B=%d,%d><C><P=0,0>", i, i*2, i*3, i*4)
_ = val
}
}
func BenchmarkStringsConcat_strconvItoa(b *testing.B) {
for i := 0; i < b.N; i++ {
val := "<P=" + strconv.Itoa(i) + "," + strconv.Itoa(i*2) + "><C=FFFFFF><B=" + strconv.Itoa(i*3) + "," + strconv.Itoa(i*4) + "><C><P=0,0>"
_ = val
}
}