Sha256: 850b0d9dd51388374bd54dd90b0f5143017f7c03fb0b25957299cd94c8ce86ef

Contents?: true

Size: 714 Bytes

Versions: 1

Compression:

Stored size: 714 Bytes

Contents

#!/usr/bin/env ruby

root_dir = File.expand_path(File.join(File.dirname(__FILE__),'..'))
lib_dir = File.join(root_dir,'lib')
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)

require 'benchmark'
require 'combinatorics/list_comprehension'

Benchmark.bm(12) do |b|
  singleton_list = ([1] * 500)
  single_enum_list = [1..200, 1]
  depth_list = [1..200]

  b.report('singleton:') do
    singleton_list.comprehension.each { |list| list.last }
  end


  b.report('single-enum:') do
    single_enum_list.comprehension.each { |list| list.last }
  end

  (1..3).each do |n|
    deep_list = (depth_list * n)

    b.report("depth #{n}:") do
      deep_list.comprehension.each { |list| list.last }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
combinatorics-0.3.1 benchmarks/list_comprehension.rb