Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
8f1e885
commit 2787d87
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |