...
1
2
3
4
5 package test
6
7 import "testing"
8
9
10
11
12
13
14
15
16
17 var (
18 mulSinkI32 int32
19 mulSinkI64 int64
20 mulSinkU32 uint32
21 mulSinkU64 uint64
22 )
23
24 func BenchmarkMulconstI32(b *testing.B) {
25
26 b.Run("3", func(b *testing.B) {
27 x := int32(1)
28 for i := 0; i < b.N; i++ {
29 x *= 3
30 }
31 mulSinkI32 = x
32 })
33
34 b.Run("5", func(b *testing.B) {
35 x := int32(1)
36 for i := 0; i < b.N; i++ {
37 x *= 5
38 }
39 mulSinkI32 = x
40 })
41
42 b.Run("12", func(b *testing.B) {
43 x := int32(1)
44 for i := 0; i < b.N; i++ {
45 x *= 12
46 }
47 mulSinkI32 = x
48 })
49
50 b.Run("120", func(b *testing.B) {
51 x := int32(1)
52 for i := 0; i < b.N; i++ {
53 x *= 120
54 }
55 mulSinkI32 = x
56 })
57
58 b.Run("-120", func(b *testing.B) {
59 x := int32(1)
60 for i := 0; i < b.N; i++ {
61 x *= -120
62 }
63 mulSinkI32 = x
64 })
65
66 b.Run("65537", func(b *testing.B) {
67 x := int32(1)
68 for i := 0; i < b.N; i++ {
69 x *= 65537
70 }
71 mulSinkI32 = x
72 })
73
74 b.Run("65538", func(b *testing.B) {
75 x := int32(1)
76 for i := 0; i < b.N; i++ {
77 x *= 65538
78 }
79 mulSinkI32 = x
80 })
81 }
82
83 func BenchmarkMulconstI64(b *testing.B) {
84
85 b.Run("3", func(b *testing.B) {
86 x := int64(1)
87 for i := 0; i < b.N; i++ {
88 x *= 3
89 }
90 mulSinkI64 = x
91 })
92
93 b.Run("5", func(b *testing.B) {
94 x := int64(1)
95 for i := 0; i < b.N; i++ {
96 x *= 5
97 }
98 mulSinkI64 = x
99 })
100
101 b.Run("12", func(b *testing.B) {
102 x := int64(1)
103 for i := 0; i < b.N; i++ {
104 x *= 12
105 }
106 mulSinkI64 = x
107 })
108
109 b.Run("120", func(b *testing.B) {
110 x := int64(1)
111 for i := 0; i < b.N; i++ {
112 x *= 120
113 }
114 mulSinkI64 = x
115 })
116
117 b.Run("-120", func(b *testing.B) {
118 x := int64(1)
119 for i := 0; i < b.N; i++ {
120 x *= -120
121 }
122 mulSinkI64 = x
123 })
124
125 b.Run("65537", func(b *testing.B) {
126 x := int64(1)
127 for i := 0; i < b.N; i++ {
128 x *= 65537
129 }
130 mulSinkI64 = x
131 })
132
133 b.Run("65538", func(b *testing.B) {
134 x := int64(1)
135 for i := 0; i < b.N; i++ {
136 x *= 65538
137 }
138 mulSinkI64 = x
139 })
140 }
141
142 func BenchmarkMulconstU32(b *testing.B) {
143
144 b.Run("3", func(b *testing.B) {
145 x := uint32(1)
146 for i := 0; i < b.N; i++ {
147 x *= 3
148 }
149 mulSinkU32 = x
150 })
151
152 b.Run("5", func(b *testing.B) {
153 x := uint32(1)
154 for i := 0; i < b.N; i++ {
155 x *= 5
156 }
157 mulSinkU32 = x
158 })
159
160 b.Run("12", func(b *testing.B) {
161 x := uint32(1)
162 for i := 0; i < b.N; i++ {
163 x *= 12
164 }
165 mulSinkU32 = x
166 })
167
168 b.Run("120", func(b *testing.B) {
169 x := uint32(1)
170 for i := 0; i < b.N; i++ {
171 x *= 120
172 }
173 mulSinkU32 = x
174 })
175
176 b.Run("65537", func(b *testing.B) {
177 x := uint32(1)
178 for i := 0; i < b.N; i++ {
179 x *= 65537
180 }
181 mulSinkU32 = x
182 })
183
184 b.Run("65538", func(b *testing.B) {
185 x := uint32(1)
186 for i := 0; i < b.N; i++ {
187 x *= 65538
188 }
189 mulSinkU32 = x
190 })
191 }
192
193 func BenchmarkMulconstU64(b *testing.B) {
194
195 b.Run("3", func(b *testing.B) {
196 x := uint64(1)
197 for i := 0; i < b.N; i++ {
198 x *= 3
199 }
200 mulSinkU64 = x
201 })
202
203 b.Run("5", func(b *testing.B) {
204 x := uint64(1)
205 for i := 0; i < b.N; i++ {
206 x *= 5
207 }
208 mulSinkU64 = x
209 })
210
211 b.Run("12", func(b *testing.B) {
212 x := uint64(1)
213 for i := 0; i < b.N; i++ {
214 x *= 12
215 }
216 mulSinkU64 = x
217 })
218
219 b.Run("120", func(b *testing.B) {
220 x := uint64(1)
221 for i := 0; i < b.N; i++ {
222 x *= 120
223 }
224 mulSinkU64 = x
225 })
226
227 b.Run("65537", func(b *testing.B) {
228 x := uint64(1)
229 for i := 0; i < b.N; i++ {
230 x *= 65537
231 }
232 mulSinkU64 = x
233 })
234
235 b.Run("65538", func(b *testing.B) {
236 x := uint64(1)
237 for i := 0; i < b.N; i++ {
238 x *= 65538
239 }
240 mulSinkU64 = x
241 })
242 }
243
View as plain text