Sha256: 0a40d5b278729866663b738996e02a9d39c5496a728827dbd8164b7a0c684028
Contents?: true
Size: 1.15 KB
Versions: 13
Compression:
Stored size: 1.15 KB
Contents
### # # Shamelessly stolen from http://ariejan.net/2011/09/24/rspec-speed-up-by-tweaking-ruby-garbage-collection/ # module Rspectacular class DeferredGarbageCollection THRESHOLD = (ENV['DEFER_GC'] || 20.0).to_f def self.start cycle_garbage_collector if enabled? end def self.reconsider if enabled? && over_deferrment_threshold? cycle_garbage_collector self.garbage_last_collected_at = Time.now end end def self.cycle_garbage_collector GC.enable GC.start GC.disable end def self.over_deferrment_threshold? time_since_garbage_last_collected >= THRESHOLD end def self.enabled? THRESHOLD > 0 end def self.time_since_garbage_last_collected Time.now - garbage_last_collected_at end def self.garbage_last_collected_at @garbage_last_collected_at || Time.now end class << self attr_writer :garbage_last_collected_at end end end RSpec.configure do |config| config.before(:all) do Rspectacular::DeferredGarbageCollection.start end config.after(:all) do Rspectacular::DeferredGarbageCollection.reconsider end end
Version data entries
13 entries across 13 versions & 1 rubygems