Skip to content

Instantly share code, notes, and snippets.

@remi
Created April 1, 2014 17:55
Show Gist options
  • Save remi/9919413 to your computer and use it in GitHub Desktop.
Save remi/9919413 to your computer and use it in GitHub Desktop.
The fastest way to get the current year in Ruby
#!/usr/bin/env ruby
require 'benchmark'
require 'date'
Benchmark.bm do |x|
x.report('Time.now') { 100_000.times { Time.now.year } }
x.report('Date.today') { 100_000.times { Date.today.year } }
end
user system total real
Time.now 0.290000 0.010000 0.300000 ( 0.287891)
Date.today 0.200000 0.000000 0.200000 ( 0.202018)
@simonprev
Copy link

Évidemment, Date a moins d’éléments à "compter"/"gérer"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment