Sha256: 72c80fa1f7542b2909734f66612aa7e7a6104c4e0c6729f0378af2f7057eaf4d

Contents?: true

Size: 1.4 KB

Versions: 8

Compression:

Stored size: 1.4 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'

describe "Speccing Ruby for speed" do
  
  describe "various versions for allocation id concatenating" do
    before(:each) do
      @allocs = [:hello, :speed, :test]
      @ids = {
        :hello => (1..100_000).to_a,
        :speed => (1..5_000).to_a,
        :test => (1..1_000).to_a
      }
      GC.disable
    end
    after(:each) do
      GC.enable
      GC.start # start the GC to minimize the chance that it will run again during the speed spec
    end
    describe "+" do
      it "should be fast" do
        Benchmark.realtime do
          @allocs.inject([]) do |total, alloc|
            total + @ids[alloc]
          end
        end.should <= 0.0025
      end
    end
    describe "map and flatten!(1)" do
      it "should be fast" do
        Benchmark.realtime do
          @allocs.map { |alloc| @ids[alloc] }.flatten!(1)
        end.should <= 0.02
      end
    end
    describe "<< and flatten!(1)" do
      it "should be fast" do
        Benchmark.realtime do
          @allocs.inject([]) do |total, alloc|
            total << @ids[alloc]
          end.flatten!(1)
        end.should <= 0.02
      end
    end
    describe "<< and flatten!" do
      it "should be fast" do
        Benchmark.realtime do
          @allocs.inject([]) do |total, alloc|
            total << @ids[alloc]
          end.flatten!
        end.should <= 0.02
      end
    end
  end
  
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
picky-0.0.9 spec/specific/speed_spec.rb
picky-0.0.8 spec/specific/speed_spec.rb
picky-0.0.7 spec/specific/speed_spec.rb
picky-0.0.6 spec/specific/speed_spec.rb
picky-0.0.5 spec/specific/speed_spec.rb
picky-0.0.4 spec/specific/speed_spec.rb
picky-0.0.3 spec/specific/speed_spec.rb
picky-0.0.2 spec/specific/speed_spec.rb