Sha256: 16fe9c7344e0b073466cc50dac4d5844c3b6c066f6878876052e56c3dde6f671
Contents?: true
Size: 1.9 KB
Versions: 3
Compression:
Stored size: 1.9 KB
Contents
# encoding: utf-8 # require 'spec_helper' describe "Memory optimization" do before(:each) do # Remove all indexes. Picky::Indexes.clear_indexes @index = Picky::Index.new :memory_optimization do category :text1 category :text2 category :text3 category :text4 end @thing = Struct.new(:id, :text1, :text2, :text3, :text4) end attr_reader :index, :thing it 'saves memory' do require 'objspace' GC.start memsize_without_added_thing = ObjectSpace.memsize_of_all(Array) GC.start index.add thing.new(1, 'one', 'two', 'three', 'four') GC.start memsize_with_added_thing = ObjectSpace.memsize_of_all(Array) GC.start memsize_with_added_thing.should > memsize_without_added_thing Picky::Indexes.optimize_memory GC.start memsize_with_optimized_memory = ObjectSpace.memsize_of_all(Array) GC.start # Still larger than with nothing. memsize_without_added_thing.should < memsize_with_optimized_memory # But smaller than with added. memsize_with_optimized_memory.should < memsize_with_added_thing end it 'saves a certain amount of memory' do require 'objspace' GC.start memsize_without_added_thing = ObjectSpace.memsize_of_all(Array) GC.start index.add thing.new(1, 'one', 'two', 'three', 'four') GC.start memsize_with_added_thing = ObjectSpace.memsize_of_all(Array) GC.start 10.times do |i| index.add thing.new(i+1, 'one', 'two', 'three', 'four') end GC.start memsize_with_readded_thing = ObjectSpace.memsize_of_all(Array) GC.start Picky::Indexes.optimize_memory GC.start memsize_with_optimized_memory = ObjectSpace.memsize_of_all(Array) GC.start # Optimize saves some memory. (memsize_with_optimized_memory + 2000).should <= memsize_with_readded_thing end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
picky-4.31.3 | spec/functional/optimize_memory_spec.rb |
picky-4.31.2 | spec/functional/optimize_memory_spec.rb |
picky-4.31.1 | spec/functional/optimize_memory_spec.rb |