Git Product home page Git Product logo

Comments (9)

eregon avatar eregon commented on June 15, 2024 1

Ah from the linked PR you actually used 1ms.
Then it might be more realistic to fix this, although I don't remember the details.
Not sure how it's possible we get 0 samples, should be at least one.

from benchmark-ips.

ivoanjo avatar ivoanjo commented on June 15, 2024

Huh! Out of curiosity, benchmark-ips also isn't very happy if the test time is too short:

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'

  gem 'benchmark-ips'
end

Benchmark.ips do |x|
  x.config(:warmup => 1, :time => 0.000000001)
  x.report("addition") { 1 + 2 }
  x.compare!
end

result:

$ ruby bench-ips-testcase.rb
Warming up --------------------------------------
            addition     2.741M i/100ms
Calculating -------------------------------------
            additionTraceback (most recent call last):
	11: from bench-ips-testcase.rb:9:in `<main>'
	10: from /Users/ivo.anjo/.rvm/gems/ruby-2.7.5/gems/benchmark-ips-2.9.2/lib/benchmark/ips.rb:53:in `ips'
	 9: from /Users/ivo.anjo/.rvm/gems/ruby-2.7.5/gems/benchmark-ips-2.9.2/lib/benchmark/ips/job.rb:254:in `run'
	 8: from /Users/ivo.anjo/.rvm/gems/ruby-2.7.5/gems/benchmark-ips-2.9.2/lib/benchmark/ips/job.rb:254:in `times'
	 7: from /Users/ivo.anjo/.rvm/gems/ruby-2.7.5/gems/benchmark-ips-2.9.2/lib/benchmark/ips/job.rb:255:in `block in run'
	 6: from /Users/ivo.anjo/.rvm/gems/ruby-2.7.5/gems/benchmark-ips-2.9.2/lib/benchmark/ips/job.rb:312:in `run_benchmark'
	 5: from /Users/ivo.anjo/.rvm/gems/ruby-2.7.5/gems/benchmark-ips-2.9.2/lib/benchmark/ips/job.rb:312:in `each'
	 4: from /Users/ivo.anjo/.rvm/gems/ruby-2.7.5/gems/benchmark-ips-2.9.2/lib/benchmark/ips/job.rb:351:in `block in run_benchmark'
	 3: from /Users/ivo.anjo/.rvm/gems/ruby-2.7.5/gems/benchmark-ips-2.9.2/lib/benchmark/ips/job.rb:367:in `create_stats'
	 2: from /Users/ivo.anjo/.rvm/gems/ruby-2.7.5/gems/benchmark-ips-2.9.2/lib/benchmark/ips/job.rb:367:in `new'
	 1: from /Users/ivo.anjo/.rvm/gems/ruby-2.7.5/gems/benchmark-ips-2.9.2/lib/benchmark/ips/stats/sd.rb:11:in `initialize'
/Users/ivo.anjo/.rvm/gems/ruby-2.7.5/gems/benchmark-ips-2.9.2/lib/benchmark/timing.rb:12:in `mean': undefined method `/' for nil:NilClass (NoMethodError)

To add context on why anyone would want to run a "benchmark" with low warmup (and low time), it's because we run benchmarks separately from our usual test suite, and it happened in the past that we broke our benchmarks but CI was still green.

So now we run the benchmarks for a really short time in CI just to validate that they're working, and get faster feedback when we broke them.

from benchmark-ips.

eregon avatar eregon commented on June 15, 2024

That warmup is 0.1ns and the time 1ns, it's basically impossible to measure such small times, i.e., clock_gettime actually takes longer to run.
Do you still get the error if you use something more reasonable like 1ms?

from benchmark-ips.

ivoanjo avatar ivoanjo commented on June 15, 2024

Yup, we were using 1ms, I'm guessing because of noisy neighbors (container inside VM inside possibly-shared-CI-machine) we got unlucky from time to time.

I reduced it a lot in the example to trigger it with certainty.

I suspect the issue may come from

before = Timing.now
target = Timing.add_second before, @warmup / 2.0
cycles = 1
warmup_iter = 1
warmup_time_us = 0.0
while Timing.now + warmup_time_us * 2 < target
-- if target is small enough, then by the time it gets to the check, time's over, and the loop never runs.

from benchmark-ips.

nateberkopec avatar nateberkopec commented on June 15, 2024

Makes sense to fix. Agreed that "we should get at least one sample" is a common-sense fix here.

from benchmark-ips.

eregon avatar eregon commented on June 15, 2024

That looks like a bug in the code I added there, whoops.
I can try to make a PR but I'm not sure when I'll have time.
If anyone else want to fix it I'm happy to review.

from benchmark-ips.

eregon avatar eregon commented on June 15, 2024

Fix in #121

from benchmark-ips.

eregon avatar eregon commented on June 15, 2024

Also for your use case and with that fix, x.config(warmup: 0, time: 0) is probably the best because that runs a single iteration, a non-zero warmup means at least 2 iterations total.

from benchmark-ips.

ivoanjo avatar ivoanjo commented on June 15, 2024

Also for your use case and with that fix, x.config(warmup: 0, time: 0) is probably the best because that runs a single iteration, a non-zero warmup means at least 2 iterations total.

👍 Thanks for the tip and thanks for the fix :)

from benchmark-ips.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.