-
Notifications
You must be signed in to change notification settings - Fork 3
/
formatter_benchmark_test.go
79 lines (71 loc) · 2.02 KB
/
formatter_benchmark_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
package stringFormatter
import (
"fmt"
"testing"
"time"
)
func BenchmarkFormat4Arg(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = Format(
"Today is : {0}, atmosphere pressure is : {1} mmHg, temperature: {2}, location: {3}",
time.Now().String(), 725, -1.54, "Yekaterinburg",
)
}
}
func BenchmarkFormat4ArgAdvanced(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = Format(
"Today is : {0}, atmosphere pressure is : {1:E2} mmHg, temperature: {2:E3}, location: {3}",
time.Now().String(), 725, -15.54, "Yekaterinburg",
)
}
}
func BenchmarkFmt4Arg(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = fmt.Sprintf(
"Today is : %s, atmosphere pressure is : %d mmHg, temperature: %f, location: %s",
time.Now().String(), 725, -1.54, "Yekaterinburg",
)
}
}
func BenchmarkFmt4ArgAdvanced(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = fmt.Sprintf(
"Today is : %s, atmosphere pressure is : %.3e mmHg, temperature: %.2f, location: %s",
time.Now().String(), 725.0, -15.54, "Yekaterinburg",
)
}
}
func BenchmarkFormat6Arg(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = Format(
"Today is : {0}, atmosphere pressure is : {1} mmHg, temperature: {2}, location: {3}, coord:{4}-{5}",
time.Now().String(), 725, -1.54, "Yekaterinburg", "64.245", "37.895",
)
}
}
func BenchmarkFmt6Arg(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = fmt.Sprintf(
"Today is : %s, atmosphere pressure is : %d mmHg, temperature: %f, location: %s, coords: %s-%s",
time.Now().String(), 725, -1.54, "Yekaterinburg", "64.245", "37.895",
)
}
}
func BenchmarkFormatComplex7Arg(b *testing.B) {
args := map[string]any{
"temperature": -10,
"location": "Yekaterinburg",
"time": time.Now().String(),
"pressure": 725,
"humidity": 34,
"longitude": "64.245",
"latitude": "35.489",
}
for i := 0; i < b.N; i++ {
_ = FormatComplex(
"Today is : {time}, atmosphere pressure is : {pressure} mmHg, humidity: {humidity}, temperature: {temperature}, location: {location}, coords:{longitude}-{latitude}",
args,
)
}
}