Sha256: 571f9ee64f79ce89b2bc8055dea7136062a23b533cd177aa470920f527367aa4

Contents?: true

Size: 854 Bytes

Versions: 21

Compression:

Stored size: 854 Bytes

Contents

require 'benchmark'

n = 10000

list = 1.upto(10).to_a

Benchmark.benchmark do |bm|
  puts "take_while"
  3.times do
    bm.report do
      n.times do
        list.
          take_while {|i| i < 6}.
          map {|i| i}.
          compact
      end
    end
  end

  puts

  puts "list[0,n]"
  3.times do
    bm.report do
      n.times do
        if index = list.index(6)
          list[0, index].map {|i| i.to_s}
        else
          list.map {|i| i}.compact
        end
      end
    end
  end
end

__END__

ruby benchmarks/index_v_take_while.rb
take_while
   0.020000   0.000000   0.020000 (  0.020005)
   0.010000   0.000000   0.010000 (  0.015907)
   0.010000   0.000000   0.010000 (  0.015962)

list[0,n]
   0.020000   0.000000   0.020000 (  0.023561)
   0.020000   0.000000   0.020000 (  0.018812)
   0.030000   0.000000   0.030000 (  0.022389)

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
opal-rspec-1.1.0.alpha3 rspec-core/upstream/benchmarks/index_v_take_while.rb
opal-rspec-1.1.0.alpha2 rspec-core/upstream/benchmarks/index_v_take_while.rb
opal-rspec-1.1.0.alpha1 rspec-core/upstream/benchmarks/index_v_take_while.rb
opal-rspec-1.0.0 rspec-core/upstream/benchmarks/index_v_take_while.rb
opal-rspec-1.0.0.alpha1 rspec-core/upstream/benchmarks/index_v_take_while.rb
opal-rspec-0.8.0 rspec-core/upstream/benchmarks/index_v_take_while.rb
opal-rspec-0.8.0.alpha3 rspec-core/upstream/benchmarks/index_v_take_while.rb
opal-rspec-0.8.0.alpha2 rspec-core/upstream/benchmarks/index_v_take_while.rb
opal-rspec-0.8.0.alpha1 rspec-core/upstream/benchmarks/index_v_take_while.rb
opal-rspec-0.7.1 rspec-core/upstream/benchmarks/index_v_take_while.rb
opal-rspec-0.7.0 rspec-core/upstream/benchmarks/index_v_take_while.rb
opal-rspec-0.6.2 rspec-core/benchmarks/index_v_take_while.rb
opal-rspec-0.7.0.rc.2 rspec-core/upstream/benchmarks/index_v_take_while.rb
opal-rspec-0.6.1 rspec-core/benchmarks/index_v_take_while.rb
opal-rspec-0.6.0 rspec-core/benchmarks/index_v_take_while.rb
opal-rspec-0.6.0.beta1 rspec-core/benchmarks/index_v_take_while.rb
opal-connect-rspec-0.5.0 rspec-core/benchmarks/index_v_take_while.rb
opal-rspec-0.5.0 rspec-core/benchmarks/index_v_take_while.rb
opal-rspec-0.5.0.beta3 rspec-core/benchmarks/index_v_take_while.rb
opal-rspec-0.5.0.beta2 rspec-core/benchmarks/index_v_take_while.rb