- Ruby 初心者スレッド Part 66
535 :デフォルトの名無しさん (ワッチョイ 275f-8Kp1)[sage]:2020/05/23(土) 20:20:01.68 ID:x0bVPHOi0 - >>534
# gem install benchmark_driver require 'benchmark_driver' Benchmark.driver do |x| x.prelude %{ input = (1..2_000_000).to_a.shuffle RUBY x.report 'push without size', %{o = []; input.each{|x| o.push x }} x.report '[]= with size (each_with_index)', %{o = Array.new(input.size); input.each_with_index{|x,ix| o[ix] = x }} x.report '[]= with size (each)', %{o = Array.new(input.size); i=0; input.each{|x| o[i] = x;i+=1 }} x.report 'block with size', %{o = Array.new(input.size){|x| input[x] }} end
|