Skip to content

Instantly share code, notes, and snippets.

@pda
Created August 3, 2011 05:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pda/1121972 to your computer and use it in GitHub Desktop.
Save pda/1121972 to your computer and use it in GitHub Desktop.
Faster RSpec with manual garbage collection
##
# spec/support/garbage_collection.rb
#
# Inspired by:
# http://www.rubyinside.com/careful-cutting-to-get-faster-rspec-runs-with-rails-5207.html
#
# At time of writing:
# reduces duration from ~16.7sec to ~15.7sec (6% improvement)
# increases peak memory usage from 150mb to 200mb (33% increase)
RSpec.configure do |config|
config.before(:suite) { GC.disable }
config.after(:suite) { GC.enable }
example_counter = 0
config.after(:each) do
if example_counter % 32 == 0
GC.enable
GC.start
GC.disable
end
example_counter += 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment