LoginSignup
7
6

More than 5 years have passed since last update.

日付オブジェクトの生成には Time.local を使おう

Posted at

日付のオブジェクトを生成する場合、Time.parse はとても遅いので Time.local を使うようにしましょう。

n = 100000
Benchmark.bm(20) do |x|
x.report("Time.parse") { n.times { Time.parse("2012-12-01") } }
x.report("Time.local") { n.times { Time.local(2012, 12, 1) } }
end 

#=>
user     system      total        real
Time.parse            6.630000   0.020000   6.650000 (  6.653874)
Time.local            0.270000   0.010000   0.280000 (  0.270010)
7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6