-
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
Show retained difference #9
Comments
Can you please provide a simpler example without external libraries, like Grape? |
require 'set'
require 'benchmark/memory'
class Retainer
attr_reader :setup
def initialize
@setup = []
end
def retain!
@setup << { x: 1 }
end
end
r = Retainer.new
setup_ar = r.instance_variable_get(:@setup).to_a
setup_set = r.instance_variable_get(:@setup).to_set
Benchmark.memory do |b|
calls = 10001
b.report('using Array') do
r.instance_variable_set(:@setup, setup_ar)
calls.times { r.retain! }
end
b.report('using Set') do
r.instance_variable_set(:@setup, setup_set)
calls.times { r.retain! }
end
b.compare!
end The output is:
Desired output to include the retained difference of 10K objects vs. 1 object. |
It's still not "10K objects vs. 1 object.", but a bit different from yours. Now I'm going to fix bench, I guess there is a fundamental error, in approach. |
OK, there is no fundamental errors in approach (
|
I see what's going on, thanks. The output is clear in terms of results with |
I don't know, I guess it's up to MRI. If GC doesn't run here (even if you'd replace |
Closing in favor of the GC question, #12. |
Thanks @AlexWayfer for helping me work through this. |
I don't think it's different issues, like we could leave this one, but… as you wish.
You're welcome. I'm interesting in correct benchmarks. |
tl;dr How do I show retained difference in
compare!
?Coming from ruby-grape/grape#2102 (comment), the amount of memory allocated is the same, but we are retaining many more objects. Want to highlight that since we're trying to track a leak.
The text was updated successfully, but these errors were encountered: