Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep iterations below 2**30 #143

Merged
merged 1 commit into from
Feb 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/benchmark/ips/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class Job
# The percentage of the expected runtime to allow
# before reporting a weird runtime
MAX_TIME_SKEW = 0.05
POW_2_30 = 1 << 30
# Keep iterations below this to avoid overflow to 64-bit long or Bignum
MAX_ITERATIONS = 1 << 30

# Two-element arrays, consisting of label and block pairs.
# @return [Array<Entry>] list of entries
Expand Down Expand Up @@ -296,11 +297,13 @@ def run_warmup

# If the number of cycles would go outside the 32-bit signed integers range
# then exit the loop to avoid overflows and start the 100ms warmup runs
break if cycles >= POW_2_30
break if cycles >= MAX_ITERATIONS
cycles *= 2
end while Timing.now + warmup_time_us * 2 < target

cycles = cycles_per_100ms warmup_time_us, warmup_iter
per_100ms = cycles_per_100ms warmup_time_us, warmup_iter
# Not [per_100ms, MAX_ITERATIONS].min as that can promote the result to long
cycles = per_100ms > MAX_ITERATIONS ? MAX_ITERATIONS : per_100ms
@timing[item] = cycles

# Run for the remaining of warmup in a similar way as #run_benchmark.
Expand Down