Coswell Productions

Slice and dice Cucumber run-times

Inspired by The road to faster tests and Crank Your Specs, I decided to apply the delayed/enforced garbage collector technique to a fairly large Cucumber test suite that I have. Here's the code that goes in your env.rb file:

last_gc_run = Time.now

Before do
  GC.disable
end

After do
  if Time.now - last_gc_run > 2.0
    GC.enable
    GC.start
    last_gc_run = Time.now
  end
end

and the Cucumber and perftool.rb results from before the change:

74 scenarios (74 passed)
793 steps (793 passed)
3m19.785s

Total: 9642 samples
    2908  30.2%  30.2%     2908  30.2% garbage_collector
     873   9.1%  39.2%      970  10.1% Timeout.timeout
     386   4.0%  43.2%     1583  16.4% Open3.popen3

and after:

74 scenarios (74 passed)
793 steps (793 passed)
2m42.195s

Total: 6828 samples
    1085  15.9%  15.9%     1085  15.9% garbage_collector
     583   8.5%  24.4%      697  10.2% Timeout.timeout
     485   7.1%  31.5%     4877  71.4% Object#instance_exec

That's another minute or so of my life per test run that I'll put to good use somehow.

See what else is here...