Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Deferring garbage collection cuts the time to run the test suite down (

…#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...
commit 2787d87138957e3c7cf82ba162b9ededb143955d 1 parent 8f1e885
@justinfrench authored
Showing with 31 additions and 0 deletions.
  1. +10 −0 spec/spec_helper.rb
  2. +21 −0 spec/support/deferred_garbage_collection.rb
View
10 spec/spec_helper.rb
@@ -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
View
21 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
Please sign in to comment.
Something went wrong with that request. Please try again.