a = (1..1000000).to_a Benchmark.bmbm do |bm| bm.report('a に追加'){a.delete_at(0); a.push("s")} end a = (1..1000000).to_a Benchmark.bmbm do |bm| bm.report('部分参照して追加'){a[1..-1].push("s")} end
結果: user system total real a に追加 0.050000 0.000000 0.050000 ( 0.048458) user system total real 部分参照して追加 0.050000 0.010000 0.060000 ( 0.053062)