Created
August 3, 2011 05:34
-
-
Save pda/1121972 to your computer and use it in GitHub Desktop.
Faster RSpec with manual garbage collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# 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