class RSpec::Core::Configuration
Extensions to RSpec::Core::Configuration
to allow configuration of desired GC behavior.
Public Class Methods
new()
click to toggle source
Overridden constructor to initialize ‘gc_every_n_examples` to 0. This disables the explicit GC control.
# File lib/rspec-gc-control/configuration.rb, line 16 def initialize initialize_without_gc @gc_every_n_examples = 0 end
Also aliased as: initialize_without_gc
Public Instance Methods
gc_every_n_examples=(n)
click to toggle source
If set to a value above 0, turns automatic GC off and runs it only every N tests, which can result in higher peak memory usage but lower total execution time.
# File lib/rspec-gc-control/configuration.rb, line 43 def gc_every_n_examples=(n) if(defined?(JRuby)) warn "Ignoring gc_every_n_examples because JRuby doesn't support GC control." return end if(!GC.respond_to?(:count)) warn "Ignoring gc_every_n_examples because this Ruby implementation doesn't implement GC.count." return end @gc_every_n_examples = n if(@gc_every_n_examples > 0) GC.disable else GC.enable end end
gc_if_needed()
click to toggle source
@private
# File lib/rspec-gc-control/configuration.rb, line 22 def gc_if_needed gc_time = 0 if(@gc_every_n_examples > 0) @test_counter = -1 if(!defined?(@test_counter)) @test_counter += 1 if(@test_counter >= (@gc_every_n_examples - 1)) t_before = Time.now GC.enable GC.start GC.disable gc_time = Time.now - t_before @test_counter = 0 end end return gc_time end