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