forked from mna/gocostmodel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conv_test.go
63 lines (53 loc) · 956 Bytes
/
conv_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
package gocostmodel
import (
"strconv"
"testing"
)
var (
s2i = "2"
i2s string
str = "abcd"
s2b []byte
bt = []byte{'a', 'b', 'c', 'd'}
b2s string
)
func BenchmarkConvIntToFloat64(b *testing.B) {
for i := 0; i < b.N; i++ {
d1 = float64(i1)
}
}
func BenchmarkConvFloat64ToInt(b *testing.B) {
for i := 0; i < b.N; i++ {
i1 = int(d1)
}
}
func BenchmarkConvIntToFloat32(b *testing.B) {
for i := 0; i < b.N; i++ {
f1 = float32(i1)
}
}
func BenchmarkConvFloat32ToInt(b *testing.B) {
for i := 0; i < b.N; i++ {
i1 = int(f1)
}
}
func BenchmarkConvStringToInt(b *testing.B) {
for i := 0; i < b.N; i++ {
i1, _ = strconv.Atoi(s2i)
}
}
func BenchmarkConvIntToString(b *testing.B) {
for i := 0; i < b.N; i++ {
i2s = strconv.Itoa(i1)
}
}
func BenchmarkStringToByte(b *testing.B) {
for i := 0; i < b.N; i++ {
s2b = []byte(str)
}
}
func BenchmarkByteToString(b *testing.B) {
for i := 0; i < b.N; i++ {
b2s = string(bt)
}
}