...
1
2
3
4
5 package test
6
7 import (
8 "testing"
9 )
10
11 var Output int
12
13 func BenchmarkDiv64UnsignedSmall(b *testing.B) {
14 q := uint64(1)
15 for i := 1; i <= b.N; i++ {
16 q = (q + uint64(i)) / uint64(i)
17 }
18 Output = int(q)
19 }
20
21 func BenchmarkDiv64Small(b *testing.B) {
22 q := int64(1)
23 for i := 1; i <= b.N; i++ {
24 q = (q + int64(i)) / int64(i)
25 }
26 Output = int(q)
27 }
28
29 func BenchmarkDiv64SmallNegDivisor(b *testing.B) {
30 q := int64(-1)
31 for i := 1; i <= b.N; i++ {
32 q = (int64(i) - q) / -int64(i)
33 }
34 Output = int(q)
35 }
36
37 func BenchmarkDiv64SmallNegDividend(b *testing.B) {
38 q := int64(-1)
39 for i := 1; i <= b.N; i++ {
40 q = -(int64(i) - q) / int64(i)
41 }
42 Output = int(q)
43 }
44
45 func BenchmarkDiv64SmallNegBoth(b *testing.B) {
46 q := int64(1)
47 for i := 1; i <= b.N; i++ {
48 q = -(int64(i) + q) / -int64(i)
49 }
50 Output = int(q)
51 }
52
53 func BenchmarkDiv64Unsigned(b *testing.B) {
54 q := uint64(1)
55 for i := 1; i <= b.N; i++ {
56 q = (uint64(0x7fffffffffffffff) - uint64(i) - (q & 1)) / uint64(i)
57 }
58 Output = int(q)
59 }
60
61 func BenchmarkDiv64(b *testing.B) {
62 q := int64(1)
63 for i := 1; i <= b.N; i++ {
64 q = (int64(0x7fffffffffffffff) - int64(i) - (q & 1)) / int64(i)
65 }
66 Output = int(q)
67 }
68
69 func BenchmarkDiv64NegDivisor(b *testing.B) {
70 q := int64(-1)
71 for i := 1; i <= b.N; i++ {
72 q = (int64(0x7fffffffffffffff) - int64(i) - (q & 1)) / -int64(i)
73 }
74 Output = int(q)
75 }
76
77 func BenchmarkDiv64NegDividend(b *testing.B) {
78 q := int64(-1)
79 for i := 1; i <= b.N; i++ {
80 q = -(int64(0x7fffffffffffffff) - int64(i) - (q & 1)) / int64(i)
81 }
82 Output = int(q)
83 }
84
85 func BenchmarkDiv64NegBoth(b *testing.B) {
86 q := int64(-1)
87 for i := 1; i <= b.N; i++ {
88 q = -(int64(0x7fffffffffffffff) - int64(i) - (q & 1)) / -int64(i)
89 }
90 Output = int(q)
91 }
92
93 func BenchmarkMod64UnsignedSmall(b *testing.B) {
94 r := uint64(1)
95 for i := 1; i <= b.N; i++ {
96 r = (uint64(i) + r) % uint64(i)
97 }
98 Output = int(r)
99 }
100
101 func BenchmarkMod64Small(b *testing.B) {
102 r := int64(1)
103 for i := 1; i <= b.N; i++ {
104 r = (int64(i) + r) % int64(i)
105 }
106 Output = int(r)
107 }
108
109 func BenchmarkMod64SmallNegDivisor(b *testing.B) {
110 r := int64(-1)
111 for i := 1; i <= b.N; i++ {
112 r = (int64(i) - r) % -int64(i)
113 }
114 Output = int(r)
115 }
116
117 func BenchmarkMod64SmallNegDividend(b *testing.B) {
118 r := int64(-1)
119 for i := 1; i <= b.N; i++ {
120 r = -(int64(i) - r) % int64(i)
121 }
122 Output = int(r)
123 }
124
125 func BenchmarkMod64SmallNegBoth(b *testing.B) {
126 r := int64(1)
127 for i := 1; i <= b.N; i++ {
128 r = -(int64(i) + r) % -int64(i)
129 }
130 Output = int(r)
131 }
132
133 func BenchmarkMod64Unsigned(b *testing.B) {
134 r := uint64(1)
135 for i := 1; i <= b.N; i++ {
136 r = (uint64(0x7fffffffffffffff) - uint64(i) - (r & 1)) % uint64(i)
137 }
138 Output = int(r)
139 }
140
141 func BenchmarkMod64(b *testing.B) {
142 r := int64(1)
143 for i := 1; i <= b.N; i++ {
144 r = (int64(0x7fffffffffffffff) - int64(i) - (r & 1)) % int64(i)
145 }
146 Output = int(r)
147 }
148
149 func BenchmarkMod64NegDivisor(b *testing.B) {
150 r := int64(-1)
151 for i := 1; i <= b.N; i++ {
152 r = (int64(0x7fffffffffffffff) - int64(i) - (r & 1)) % -int64(i)
153 }
154 Output = int(r)
155 }
156
157 func BenchmarkMod64NegDividend(b *testing.B) {
158 r := int64(-1)
159 for i := 1; i <= b.N; i++ {
160 r = -(int64(0x7fffffffffffffff) - int64(i) - (r & 1)) % int64(i)
161 }
162 Output = int(r)
163 }
164
165 func BenchmarkMod64NegBoth(b *testing.B) {
166 r := int64(1)
167 for i := 1; i <= b.N; i++ {
168 r = -(int64(0x7fffffffffffffff) - int64(i) - (r & 1)) % -int64(i)
169 }
170 Output = int(r)
171 }
172
View as plain text