-
Notifications
You must be signed in to change notification settings - Fork 6
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
Should GC.start be run before reporting results? #12
Comments
Good question, @dblock. I think that makes sense to me. Apologies for the delay in response! |
I can try to make a PR, if you want. |
Don't let me stop by @AlexWayfer :) |
Alright, digging in here. If I am understanding the intent of the benchmark, this is a clearer way to write it: Benchmark coderequire 'set'
require 'benchmark/memory'
class Retainer
def initialize(container)
@container = container
end
def retain!
@container << { x: 1 }
end
end
ra = Retainer.new([])
rs = Retainer.new(Set.new)
Benchmark.memory do |b|
calls = 10_001
b.report('using Array') do
calls.times { ra.retain! }
end
b.report('using Set') do
calls.times { rs.retain! }
end
b.compare!
end Running this gives the following output: Benchmark output
If I'm understanding the source of the question, you were finding this confusing because the report is about the magnitude of allocations rather than the magnitude of retentions. In that case, I don't think that calling I think what I would like to do to address this is twofold:
(1) would make the output less confusing by default and (2) would allow you to tune the tool to be better suited for testing memory leaks. What do you think? Would those two changes have made the situation less confusing? |
I'm reviewing the original report and a bit confused: Yeah, |
Coming from #9. Output was confusing without
GC.start
.The text was updated successfully, but these errors were encountered: