Commit 42c5c70
committed
hoist overflow check from for each num to on usage
This was done to have less branches in the hot path for numbers, thus
has little to no impact on shorter inputs, still a ~5% improvement:
After the change:
goos: linux
goarch: amd64
pkg: github.com/xnacly/go-iso8601-duration
cpu: AMD Ryzen 7 3700X 8-Core Processor
BenchmarkDuration/P0D-16 100000000 10.01 ns/op
BenchmarkDuration/PT15H-16 100000000 11.81 ns/op
BenchmarkDuration/P1W-16 100000000 10.19 ns/op
BenchmarkDuration/P15W-16 120588932 9.779 ns/op
BenchmarkDuration/P1Y15W-16 86265106 13.76 ns/op
BenchmarkDuration/P15Y-16 122859478 9.910 ns/op
BenchmarkDuration/P15Y3M-16 77137617 14.32 ns/op
BenchmarkDuration/P15Y3M41D-16 60263616 20.74 ns/op
BenchmarkDuration/PT15M-16 96869085 12.30 ns/op
BenchmarkDuration/PT15M10S-16 63139969 18.33 ns/op
BenchmarkDuration/P3Y6M4DT12H30M5S-16 29586862 39.14 ns/op
PASS
ok github.com/xnacly/go-iso8601-duration 14.812s
Before the change:
goos: linux
goarch: amd64
pkg: github.com/xnacly/go-iso8601-duration
cpu: AMD Ryzen 7 3700X 8-Core Processor
BenchmarkDuration/P0D-16 120725466 9.931 ns/op 0 B/o 0 allocs/op
BenchmarkDuration/PT15H-16 92520681 11.67 ns/op 0 B/o 0 allocs/op
BenchmarkDuration/P1W-16 100000000 10.15 ns/op 0 B/o 0 allocs/op
BenchmarkDuration/P15W-16 100000000 10.26 ns/op 0 B/o 0 allocs/op
BenchmarkDuration/P1Y15W-16 82810779 14.83 ns/op 0 B/o 0 allocs/op
BenchmarkDuration/P15Y-16 120902158 10.29 ns/op 0 B/o 0 allocs/op
BenchmarkDuration/P15Y3M-16 75393909 15.68 ns/op 0 B/o 0 allocs/op
BenchmarkDuration/P15Y3M41D-16 56214748 22.31 ns/op 0 B/o 0 allocs/op
BenchmarkDuration/PT15M-16 91787005 12.85 ns/op 0 B/o 0 allocs/op
BenchmarkDuration/PT15M10S-16 53683030 19.45 ns/op 0 B/o 0 allocs/op
BenchmarkDuration/P3Y6M4DT12H30M5S-16 28636116 42.47 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/xnacly/go-iso8601-duration 14.860s1 parent 7c68f81 commit 42c5c70
1 file changed
Lines changed: 20 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
| 133 | + | |
138 | 134 | | |
139 | 135 | | |
140 | 136 | | |
141 | 137 | | |
142 | 138 | | |
143 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
149 | | - | |
| 150 | + | |
150 | 151 | | |
151 | 152 | | |
152 | 153 | | |
153 | 154 | | |
154 | | - | |
| 155 | + | |
155 | 156 | | |
156 | 157 | | |
157 | 158 | | |
158 | 159 | | |
159 | | - | |
| 160 | + | |
160 | 161 | | |
161 | 162 | | |
162 | 163 | | |
163 | 164 | | |
164 | | - | |
| 165 | + | |
165 | 166 | | |
166 | | - | |
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
| 174 | + | |
179 | 175 | | |
180 | 176 | | |
181 | 177 | | |
182 | 178 | | |
183 | 179 | | |
184 | 180 | | |
185 | 181 | | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
| 182 | + | |
191 | 183 | | |
192 | 184 | | |
193 | 185 | | |
194 | 186 | | |
195 | 187 | | |
196 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
197 | 192 | | |
198 | 193 | | |
199 | 194 | | |
200 | 195 | | |
201 | 196 | | |
202 | | - | |
| 197 | + | |
203 | 198 | | |
204 | 199 | | |
205 | 200 | | |
206 | 201 | | |
207 | | - | |
| 202 | + | |
208 | 203 | | |
209 | 204 | | |
210 | 205 | | |
211 | 206 | | |
212 | | - | |
| 207 | + | |
213 | 208 | | |
214 | | - | |
215 | 209 | | |
216 | 210 | | |
217 | 211 | | |
| |||
0 commit comments