From: Sylvain Joyeux Date: 2007-06-28T15:44:20+09:00 Subject: Re: when to Run the garbage collector? On Thursday 28 June 2007, Bill Kelly wrote: > From: "gz zz" > > > 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'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. It may be difficult to benchmark (or profile for that matter) code under GC: if the GC runs, you can get more than 200ms accounted to whichever method was being run. If you can afford the memory allocation of your benchmarked code, try GC.start ; GC.disable before starting the bench. -- Sylvain Joyeux