Created
April 1, 2014 17:55
-
-
Save remi/9919413 to your computer and use it in GitHub Desktop.
The fastest way to get the current year in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user system total real | |
Time.now 0.290000 0.010000 0.300000 ( 0.287891) | |
Date.today 0.200000 0.000000 0.200000 ( 0.202018) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Évidemment,
Date
a moins d’éléments à "compter"/"gérer"