Class: RSpec::Core::Configuration
- Inherits:
-
Object
- Object
- RSpec::Core::Configuration
- Defined in:
- lib/rspec-gc-control/configuration.rb
Overview
Extensions to RSpec::Core::Configuration to allow configuration of desired GC behavior.
Instance Method Summary collapse
-
#gc_every_n_examples=(n) ⇒ Object
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.
- #gc_if_needed ⇒ Object
-
#initialize ⇒ Configuration
constructor
Overridden constructor to initialize ‘gc_every_n_examples` to 0.
- #initialize_without_gc ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Overridden constructor to initialize ‘gc_every_n_examples` to 0. This disables the explicit GC control.
16 17 18 19 |
# File 'lib/rspec-gc-control/configuration.rb', line 16 def initialize initialize_without_gc @gc_every_n_examples = 0 end |
Instance Method Details
#gc_every_n_examples=(n) ⇒ Object
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.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 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 |
#initialize_without_gc ⇒ Object
12 |
# File 'lib/rspec-gc-control/configuration.rb', line 12 alias_method :initialize_without_gc, :initialize |