Sha256: 23cc63efe7dc16faa29c218929864ebbe80cb734c47734e0e0c93a2d0d5f8f12

Contents?: true

Size: 1.15 KB

Versions: 8

Compression:

Stored size: 1.15 KB

Contents

require 'spec_helper'

describe Index::Bundle do

  before(:each) do
    @category         = stub :category, :name => :some_category
    @type             = stub :type, :name => :some_type
    @partial_strategy = Cacher::Partial::Subtoken.new :down_to => 1
    @full             = Index::Bundle.new :some_name, @category, @type, @partial_strategy, nil, nil
  end

  def generate_random_keys amount
    alphabet = ('a'..'z').to_a
    (1..amount).to_a.collect! do |n|
      Array.new(20).collect! { alphabet[rand(26)] }.join.to_sym
    end
  end
  def generate_random_ids amount
    (1..amount).to_a.collect! do |_|
      Array.new(rand(100)+5).collect! do |_|
        rand(5_000_000)
      end
    end
  end

  describe 'speed' do
    context 'medium arrays' do
      before(:each) do
        random_keys  = generate_random_keys 500
        random_ids   = generate_random_ids  500
        @full.index = Hash[random_keys.zip(random_ids)]

        GC.disable
      end
      after(:each) do
        GC.enable
        GC.start
      end
      it 'should be fast' do
        Benchmark.realtime do
          @full.generate_partial
        end.should <= 0.2
      end
    end
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
picky-0.0.9 spec/lib/index/bundle_partial_generation_speed_spec.rb
picky-0.0.8 spec/lib/index/bundle_partial_generation_speed_spec.rb
picky-0.0.7 spec/lib/index/bundle_partial_generation_speed_spec.rb
picky-0.0.6 spec/lib/index/bundle_partial_generation_speed_spec.rb
picky-0.0.5 spec/lib/index/bundle_partial_generation_speed_spec.rb
picky-0.0.4 spec/lib/index/bundle_partial_generation_speed_spec.rb
picky-0.0.3 spec/lib/index/bundle_partial_generation_speed_spec.rb
picky-0.0.2 spec/lib/index/bundle_partial_generation_speed_spec.rb