spec/ext/performant_spec.rb in picky-1.3.0 vs spec/ext/performant_spec.rb in picky-1.3.1

- old
+ new

@@ -1,9 +1,9 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Performant::Array do - + describe "memory_efficient_intersect" do it "should intersect empty arrays correctly" do arys = [[3,4], [1,2,3], []] Performant::Array.memory_efficient_intersect(arys.sort_by(&:size)).should == [] @@ -40,9 +40,48 @@ # brute force performance_of { Performant::Array.memory_efficient_intersect(arys.sort_by(&:size)) }.should < 0.001 end it "should be optimal for 2 small arrays of 50/10_000" do arys = [(1..50).to_a, (10_000..20_000).to_a << 7] + + # & + performance_of do + arys.inject(arys.shift.dup) do |total, ary| + total & arys + end + end.should < 0.0015 + end + end + + describe "memory_efficient_intersect with symbols" do + it "should intersect empty arrays correctly" do + arys = [[:c,:d], [:a,:b,:c], []] + + Performant::Array.memory_efficient_intersect(arys.sort_by(&:size)).should == [] + end + it "should handle intermediate empty results correctly" do + arys = [[:e,:d], [:a,:b,:c], [:c,:d,:e,:h,:i]] + + Performant::Array.memory_efficient_intersect(arys.sort_by(&:size)).should == [] + end + it "should intersect correctly" do + arys = [[:c,:d], [:a,:b,:c], [:c,:d,:e,:h,:i]] + + Performant::Array.memory_efficient_intersect(arys.sort_by(&:size)).should == [:c] + end + it "should intersect many arrays" do + arys = [[:c,:d,:e,:f,:g], [:a,:b,:c,:e,:f,:g], [:c,:d,:e,:f,:g,:h,:i], [:a,:b,:c,:d,:e,:f,:g,:h,:i,:j], [:b,:c,:e,:f,:g,:s], [:a,:b,:c,:d,:e,:f,:g,:h,:i,:j], [:b,:c,:e,:f,:g,:s]] + + Performant::Array.memory_efficient_intersect(arys.sort_by(&:size)).should == [:c,:e,:f,:g] + end + it "should be optimal for 2 small arrays of 50/10_000" do + arys = [(:'1'..:'50').to_a, (:'10_000'..:'20_000').to_a << 7] + + # brute force + performance_of { Performant::Array.memory_efficient_intersect(arys.sort_by(&:size)) }.should < 0.001 + end + it "should be optimal for 2 small arrays of 50/10_000" do + arys = [(:'1'..:'50').to_a, (:'10_000'..:'20_000').to_a << 7] # & performance_of do arys.inject(arys.shift.dup) do |total, ary| total & arys \ No newline at end of file