...
1 package en
2
3 import (
4 "testing"
5 "time"
6
7 "github.com/go-playground/locales/currency"
8 )
9
10 func BenchmarkFmtNumber(b *testing.B) {
11
12 trans := New()
13 f64 := float64(1234567.43)
14 precision := uint64(2)
15
16 b.ResetTimer()
17
18 b.Run("", func(b *testing.B) {
19 for i := 0; i < b.N; i++ {
20 trans.FmtNumber(f64, precision)
21 }
22 })
23
24 b.Run("Parallel", func(b *testing.B) {
25
26 b.RunParallel(func(pb *testing.PB) {
27
28 for pb.Next() {
29 trans.FmtNumber(f64, precision)
30 }
31 })
32 })
33 }
34
35 func BenchmarkFmtPercent(b *testing.B) {
36
37 trans := New()
38 f64 := float64(97.05)
39 precision := uint64(2)
40
41 b.ResetTimer()
42
43 b.Run("", func(b *testing.B) {
44 for i := 0; i < b.N; i++ {
45 trans.FmtPercent(f64, precision)
46 }
47 })
48
49 b.Run("Parallel", func(b *testing.B) {
50
51 b.RunParallel(func(pb *testing.PB) {
52
53 for pb.Next() {
54 trans.FmtPercent(f64, precision)
55 }
56 })
57 })
58 }
59
60 func BenchmarkFmtCurrency(b *testing.B) {
61
62 trans := New()
63 f64 := float64(1234567.43)
64 precision := uint64(2)
65
66 b.ResetTimer()
67
68 b.Run("", func(b *testing.B) {
69 for i := 0; i < b.N; i++ {
70 trans.FmtCurrency(f64, precision, currency.USD)
71 }
72 })
73
74 b.Run("Parallel", func(b *testing.B) {
75
76 b.RunParallel(func(pb *testing.PB) {
77
78 for pb.Next() {
79 trans.FmtCurrency(f64, precision, currency.USD)
80 }
81 })
82 })
83 }
84
85 func BenchmarkFmtAccounting(b *testing.B) {
86
87 trans := New()
88 f64 := float64(1234567.43)
89 precision := uint64(2)
90
91 b.ResetTimer()
92
93 b.Run("", func(b *testing.B) {
94 for i := 0; i < b.N; i++ {
95 trans.FmtAccounting(f64, precision, currency.USD)
96 }
97 })
98
99 b.Run("Parallel", func(b *testing.B) {
100
101 b.RunParallel(func(pb *testing.PB) {
102
103 for pb.Next() {
104 trans.FmtAccounting(f64, precision, currency.USD)
105 }
106 })
107 })
108 }
109
110 func BenchmarkFmtDate(b *testing.B) {
111
112 trans := New()
113 t := time.Now()
114
115 b.ResetTimer()
116
117 b.Run("FmtDateShort", func(b *testing.B) {
118 for i := 0; i < b.N; i++ {
119 trans.FmtDateShort(t)
120 }
121 })
122
123 b.Run("FmtDateShortParallel", func(b *testing.B) {
124
125 b.RunParallel(func(pb *testing.PB) {
126
127 for pb.Next() {
128 trans.FmtDateShort(t)
129 }
130 })
131 })
132
133 b.Run("FmtDateMedium", func(b *testing.B) {
134 for i := 0; i < b.N; i++ {
135 trans.FmtDateMedium(t)
136 }
137 })
138
139 b.Run("FmtDateMediumParallel", func(b *testing.B) {
140
141 b.RunParallel(func(pb *testing.PB) {
142
143 for pb.Next() {
144 trans.FmtDateMedium(t)
145 }
146 })
147 })
148
149 b.Run("FmtDateLong", func(b *testing.B) {
150 for i := 0; i < b.N; i++ {
151 trans.FmtDateLong(t)
152 }
153 })
154
155 b.Run("FmtDateLongParallel", func(b *testing.B) {
156
157 b.RunParallel(func(pb *testing.PB) {
158
159 for pb.Next() {
160 trans.FmtDateLong(t)
161 }
162 })
163 })
164
165 b.Run("FmtDateFull", func(b *testing.B) {
166 for i := 0; i < b.N; i++ {
167 trans.FmtDateFull(t)
168 }
169 })
170
171 b.Run("FmtDateFullParallel", func(b *testing.B) {
172
173 b.RunParallel(func(pb *testing.PB) {
174
175 for pb.Next() {
176 trans.FmtDateFull(t)
177 }
178 })
179 })
180 }
181
182 func BenchmarkFmtTime(b *testing.B) {
183
184 trans := New()
185 t := time.Now()
186
187 b.ResetTimer()
188
189 b.Run("FmtTimeShort", func(b *testing.B) {
190 for i := 0; i < b.N; i++ {
191 trans.FmtTimeShort(t)
192 }
193 })
194
195 b.Run("FmtTimeShortParallel", func(b *testing.B) {
196
197 b.RunParallel(func(pb *testing.PB) {
198
199 for pb.Next() {
200 trans.FmtTimeShort(t)
201 }
202 })
203 })
204
205 b.Run("FmtTimeMedium", func(b *testing.B) {
206 for i := 0; i < b.N; i++ {
207 trans.FmtTimeMedium(t)
208 }
209 })
210
211 b.Run("FmtTimeMediumParallel", func(b *testing.B) {
212
213 b.RunParallel(func(pb *testing.PB) {
214
215 for pb.Next() {
216 trans.FmtTimeMedium(t)
217 }
218 })
219 })
220
221 b.Run("FmtTimeLong", func(b *testing.B) {
222 for i := 0; i < b.N; i++ {
223 trans.FmtTimeLong(t)
224 }
225 })
226
227 b.Run("FmtTimeLongParallel", func(b *testing.B) {
228
229 b.RunParallel(func(pb *testing.PB) {
230
231 for pb.Next() {
232 trans.FmtTimeLong(t)
233 }
234 })
235 })
236
237 b.Run("FmtTimeFull", func(b *testing.B) {
238 for i := 0; i < b.N; i++ {
239 trans.FmtTimeFull(t)
240 }
241 })
242
243 b.Run("FmtTimeFullParallel", func(b *testing.B) {
244
245 b.RunParallel(func(pb *testing.PB) {
246
247 for pb.Next() {
248 trans.FmtTimeFull(t)
249 }
250 })
251 })
252 }
253
View as plain text