Skip to content

Commit fc444b6

Browse files
syeopiteSija
andauthored
Use UInt64 to track iteration count during warm-up calculation in Benchmark::IPS (#15780)
If the warm-up duration is long enough, then the iteration count in `run_warmup` can easily exceed the 32-bit integer limit in a little under a minute, resulting in an `OverflowError`. This PR just change the tracker variable to an unsigned 64-bit integer so that an overflow is pretty much impossible You can reproduce the overflow with: ```crystal require "benchmark" # 100 seconds to be safe but I always get an overflow ~ 40 seconds in Benchmark.ips(warmup: 100.seconds, &.report("") { }) ``` I don't think there's any practical reasons someone would set the `warmup` duration to be that high, but I don't think `Benchmark.ips` should fail this easily either. Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
1 parent 3d1ffcc commit fc444b6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/benchmark/ips.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module Benchmark
6565
@items.each do |item|
6666
GC.collect
6767

68-
count = 0
68+
count = 0_u64
6969
elapsed = Time.measure do
7070
target = Time.monotonic + @warmup_time
7171

0 commit comments

Comments
 (0)