Sha256: 8a8e4ce4169307ed1d2efd4c98c63aa0054bb043bcbf33c328e30b1fa01b2f3d

Contents?: true

Size: 929 Bytes

Versions: 26

Compression:

Stored size: 929 Bytes

Contents

#!/usr/bin/env ruby

# Thanks William James!
# http://www.ruby-forum.com/topic/95519#200484
def cart_prod(*args)
  args.inject([[]]){|old,lst|
    new = []
    lst.each{|e| new += old.map{|c| c.dup << e }}
    new
  }
end

require 'benchmark'

a = [1,2,3]
b = [4,5]
Benchmark.bmbm do |x|
  x.report("native") do
    500_000.times { a.product(b) }
  end
  x.report("william-james") do |x|
    500_000.times { cart_prod(a, b) }
  end
end

# results:
# $ ruby foo.rb 
# Rehearsal -------------------------------------------------
# native          0.720000   0.000000   0.720000 (  0.729319)
# william-james   3.620000   0.010000   3.630000 (  3.629198)
# ---------------------------------------- total: 4.350000sec
# 
#                     user     system      total        real
# native          0.710000   0.000000   0.710000 (  0.708620)
# william-james   3.800000   0.000000   3.800000 (  3.792538)

# thanks for all the fish!

Version data entries

26 entries across 26 versions & 3 rubygems

Version Path
cocoapods-dependency-html-0.0.2 vendor/bundle/gems/fuzzy_match-2.0.4/THANKS-WILLIAM-JAMES.rb
cocoapods-dependency-html-0.0.1 vendor/bundle/gems/fuzzy_match-2.0.4/THANKS-WILLIAM-JAMES.rb
fuzzy_match-2.1.0 THANKS-WILLIAM-JAMES.rb
fuzzy_match-2.0.4 THANKS-WILLIAM-JAMES.rb
fuzzy_match-2.0.3 THANKS-WILLIAM-JAMES.rb
fuzzy_match-2.0.2 THANKS-WILLIAM-JAMES.rb
fuzzy_match-2.0.1 THANKS-WILLIAM-JAMES.rb
fuzzy_match-2.0.0 THANKS-WILLIAM-JAMES.rb
fuzzy_match-1.5.0 THANKS-WILLIAM-JAMES.rb
fuzzy_match-1.4.1 THANKS-WILLIAM-JAMES.rb
fuzzy_match-1.4.0 THANKS-WILLIAM-JAMES.rb
fuzzy_match-1.3.3 THANKS-WILLIAM-JAMES.rb
fuzzy_match-1.3.2 THANKS-WILLIAM-JAMES.rb
fuzzy_match-1.3.1 THANKS-WILLIAM-JAMES.rb
fuzzy_match-1.3.0 THANKS-WILLIAM-JAMES.rb
fuzzy_match-1.2.2 THANKS-WILLIAM-JAMES.rb
fuzzy_match-1.2.1 THANKS-WILLIAM-JAMES.rb
fuzzy_match-1.1.1 THANKS-WILLIAM-JAMES.rb
fuzzy_match-1.1.0 THANKS-WILLIAM-JAMES.rb
loose_tight_dictionary-1.0.5 THANKS-WILLIAM-JAMES.rb