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

Benchmark.ips does not accept Time::Span for calculation and warmup times #14758

Open
HertzDevil opened this issue Jun 26, 2024 · 0 comments · May be fixed by #14805
Open

Benchmark.ips does not accept Time::Span for calculation and warmup times #14758

HertzDevil opened this issue Jun 26, 2024 · 0 comments · May be fixed by #14805

Comments

@HertzDevil
Copy link
Contributor

The signatures of Benchmark.ips and Benchmark::IPS::Job#initialize are:

module Benchmark
  extend self

  def ips(calculation = 5, warmup = 2, interactive = STDOUT.tty?, &)
  end

  module IPS
    class Job
      def initialize(calculation = 5, warmup = 2, interactive = STDOUT.tty?)
        @warmup_time = warmup.seconds
        @calculation_time = calculation.seconds
        # ...
      end
    end
  end
end

Both calculation and warmup are durations in seconds, yet because of the Number#seconds call it is impossible to actually use a Time::Span here:

# Error: instance variable '@calculation_time' of Benchmark::IPS::Job must be Time::Span, not Int32
Benchmark.ips(5.seconds) do
end

I think those parameters should be restricted to Time::Spans, and Number arguments should be deprecated. (By the way, it seems the only other non-deprecated, public API that accepts a Number as a duration is ::sleep.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant