speeding up rspec by deferring garbage collection
-> https://makandracards.com/makandra/950-speed-up-rspec-by-deferring-garbage-collection on my machine the rspec tests went from taking 5min 02sec to 3min 29sec :O (31% improvement)
This commit is contained in:
parent
d53b7b5f9a
commit
4051651737
2 changed files with 32 additions and 0 deletions
|
|
@ -101,3 +101,13 @@ Spork.each_run do
|
||||||
AppConfig.load!
|
AppConfig.load!
|
||||||
AppConfig.setup!
|
AppConfig.setup!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# https://makandracards.com/makandra/950-speed-up-rspec-by-deferring-garbage-collection
|
||||||
|
RSpec.configure do |config|
|
||||||
|
config.before(:all) do
|
||||||
|
DeferredGarbageCollection.start
|
||||||
|
end
|
||||||
|
config.after(:all) do
|
||||||
|
DeferredGarbageCollection.reconsider
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
||||||
22
spec/support/deferred_garbage_collection.rb
Normal file
22
spec/support/deferred_garbage_collection.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
|
||||||
|
# https://makandracards.com/makandra/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
|
||||||
Loading…
Reference in a new issue