2014-01-01から1年間の記事一覧

Rubyのstringからsymbolへの変換はコロンが早い

stringからsymbolへの変換は、to_symを使うものだと思っていたけど:"hoge"でもできる。んでどっちが早いのか調べてみた。 require "benchmark" n = 1_000_000 hash = { hoge: "" } Benchmark.bm(8) do |x| 3.times do x.report("to_sym :") { n.times{hash["…