Sha256: 6b88ec9638a90dbf18d1777f5cbf4f469b42629f2d0955c4869c902531146dbc
Contents?: true
Size: 831 Bytes
Versions: 31
Compression:
Stored size: 831 Bytes
Contents
require 'benchmark' # # Benchmarking n = 100 * 100 Benchmark.bmbm do |x| x.report("Set theory") do require 'set' def set_theory(expected, actual) a = Set.new(expected) b = Set.new(actual) a == b end n.times do array = ["a", 1, {:foo => :bar}] set_theory(array, array.reverse) end end x.report("same_elements from shoulda (sorta)") do def same_elements(a1, a2) [:select, :inject, :size].each do |m| [a1, a2].each { |a| a.respond_to?(m) || return } end a1h = a1.inject({}) { |h,e| h[e] = a1.select { |i| i == e }.size; h } a2h = a2.inject({}) { |h,e| h[e] = a2.select { |i| i == e }.size; h } a1h == a2h end n.times do array = ["a", 1, {:foo => :bar}] same_elements(array, array.reverse) end end end
Version data entries
31 entries across 31 versions & 1 rubygems