-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
some examples in Readme are failing #19
Comments
Hi Jan, Thanks for trying out Given the options, I believe this is
I can see that you're testing inside the Rails app from the error messages. Please note that all the examples in the readme are tested using Ruby without any frameworks. So I'd encourage you to set up the following file outside of the Rails context for your future explorations: require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "rspec-benchmark"
end
RSpec.describe do
include RSpec::Benchmark::Matchers
...
end The first test works as expected. it "how many objects are left" do
expect { ["foo", "bar", "baz"].sort[1] }.to perform_allocation(3).and_retain(3)
end So why is your expectation failing? My guess is that Rails autoloads and potentially monkey patches some behaviour resulting in more objects being created. For example, running The second test fails. it "perform_constant" do
sizes = bench_range(8, 100_000) # => [8, 64, 512, 4096, 32768, 100000]
number_arrays = sizes.map { |n| Array.new(n) { rand(n) } }
expect { |n, i| number_arrays[i].max }.to perform_linear.in_range(8, 100_000).ratio(2)
end However, this is a configuration issue. The expectation range generates more steps than the The following test passes: it "perform_constant" do
sizes = bench_range(8, 100_000, ratio: 2)
number_arrays = sizes.map { |n| Array.new(n) { rand(n) } }
expect { |n, i| number_arrays[i].max }.to perform_linear.in_range(sizes.first, sizes.last).ratio(2)
end The benchark-trend has more explanation as to how the API works. |
Describe the problem
I am learning this gem and tried the examples in the README.
And just wann know if this is either:
Steps to reproduce the problem
Actual behaviour
Expected behaviour
Go green
Describe your environment
The text was updated successfully, but these errors were encountered: