G
gz zz
hi,I want to use ruby's garbage collector
GC.start
but when use it,and when not use it?
GC.start
but when use it,and when not use it?
From: "gz zz said:hi,I want to use ruby's garbage collector
GC.start
but when use it,and when not use it?
From: "gz zz said:Thank you.
I only see rails use the 'GC.start' in my all 'gems'.e.g.
def test_time_recognition
n = 10000
if RunTimeTests
GC.start
rectime = Benchmark.realtime do
n.times do
rs.recognize_path("content")
rs.recognize_path("content/list")
rs.recognize_path("content/show/10")
rs.recognize_path("admin/user")
rs.recognize_path("admin/user/list")
rs.recognize_path("admin/user/show/10")
end
end
puts "\n\nRecognition (RouteSet):"
per_url = rectime / (n * 6)
puts "#{per_url * 1000} ms/url"
puts "#{1 / per_url} url/s\n\n"
end
end
It may be difficult to benchmark (or profile for that matter) code underIt's doing GC.start there right before the Benchmark starts, just to
help achieve a more consistent starting point, for measuring the
elapsed time.
Notice it only does the GC.start when benchmarks are being run.
The problem is that, in real programs, the code snippet will not be the onlySeems to me it
would be better to write benchmarks that run for an amount of time that is
sufficient to ensure that the overhead of GC is consistent between runs of
the benchmark.
The problem is not the duration, but the amount of objects created.For example, don't write a benchmark that takes 0.001
seconds. Write one that takes 30 seconds, or whatever. I'm not experienced
enough with ruby yet, to know what a sensible duration is.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.