Skip to content

Commit

Permalink
Deferring garbage collection cuts the time to run the test suite down (
Browse files Browse the repository at this point in the history
…#547).

Just over a third of the time it used to take.

    # before
    Finished in 178.55 seconds
    1148 examples, 0 failures

    #after
    Finished in 66.23 seconds
    1148 examples, 0 failures
  • Loading branch information
justinfrench committed Jun 1, 2011
1 parent 8f1e885 commit 2787d87
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -349,3 +349,13 @@ def with_config(config_method_name, value, &block)
end

::ActiveSupport::Deprecation.silenced = false


Rspec.configure do |config|
config.before(:all) do
DeferredGarbageCollection.start
end
config.after(:all) do
DeferredGarbageCollection.reconsider
end
end
21 changes: 21 additions & 0 deletions spec/support/deferred_garbage_collection.rb
@@ -0,0 +1,21 @@
# Taken from http://makandra.com/notes/950-speed-up-rspec-by-deferring-garbage-collection
class DeferredGarbageCollection

DEFERRED_GC_THRESHOLD = (ENV['DEFER_GC'] || 10.0).to_f

@@last_gc_run = Time.now

def self.start
GC.disable if DEFERRED_GC_THRESHOLD > 0
end

def self.reconsider
if DEFERRED_GC_THRESHOLD > 0 && Time.now - @@last_gc_run >= DEFERRED_GC_THRESHOLD
GC.enable
GC.start
GC.disable
@@last_gc_run = Time.now
end
end

end

0 comments on commit 2787d87

Please sign in to comment.