File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -144,3 +144,34 @@ legitimate bugs. (We begin with such a case.)
144
144
this writing. Instead we put in a workaround:
145
145
146
146
https://github.com/rust-lang/rust/pull/23489
147
+
148
+ ### Overflow in benchmark iteration increment
149
+
150
+ The implementation of `#[bench]` was not prepared to deal
151
+ with an overflow in the iteration count.
152
+
153
+ The arithmetic overflow checking forced that to fail on a
154
+ benchmark like
155
+
156
+ ```rust
157
+ #[bench]
158
+ fn foo(b: &mut test::Bencher) {}
159
+ ```
160
+
161
+ rather than return bogus results.
162
+
163
+ The iteration count is stored in a `u64`, so overflow sounds
164
+ unlikely -- even though `n` is being multiplied by 2 on every
165
+ increment, so it sounds plausible that we could get to very large
166
+ numbers indeed, the fact that we have to actually *run* that many
167
+ iterations is what gives me pause.
168
+
169
+ At this point I am assuming that the compiler is doing something
170
+ to optimize away the looping when the benchmark code is empty:
171
+ keep in mind that the `#[bench]` code above is not calling the
172
+ `black_box` method of `b`. Maybe we should be requring that?
173
+
174
+ Anyway, the chosen fix was to just return the results so far before
175
+ hitting the overflow:
176
+
177
+ https://github.com/rust-lang/rust/pull/23127
You can’t perform that action at this time.
0 commit comments