Skip to content

Instantly share code, notes, and snippets.

@Fluxx
Created July 31, 2011 19:50
Show Gist options
  • Save Fluxx/1117138 to your computer and use it in GitHub Desktop.
Save Fluxx/1117138 to your computer and use it in GitHub Desktop.
require 'date'
require 'benchmark'
puts "patchlevel: #{RUBY_PATCHLEVEL}, release_date: #{RUBY_RELEASE_DATE}, ruby_version: #{RUBY_VERSION}, ruby_platform: #{RUBY_PLATFORM}"
puts '*'*80
Benchmark.bm(10) do |bm|
bm.report("Date.today") do
500_000.times { Date.today }
end
bm.report("Date.new") do
500_000.times { Date.new(2011, rand(11)+1, rand(27)+1) }
end
end
puts
193_test ❯ rvm ruby date_test.rb
patchlevel: 334, release_date: 2011-02-18, ruby_version: 1.8.7, ruby_platform: i686-darwin10.7.1
********************************************************************************
user system total real
Date.today 10.680000 0.000000 10.680000 ( 10.680279)
Date.new 14.360000 0.010000 14.370000 ( 14.365198)
patchlevel: 180, release_date: 2011-02-18, ruby_version: 1.9.2, ruby_platform: x86_64-darwin10.7.1
********************************************************************************
user system total real
Date.today 3.330000 0.010000 3.340000 ( 3.335872)
Date.new 2.940000 0.000000 2.940000 ( 2.941093)
patchlevel: -1, release_date: 2011-07-31, ruby_version: 1.9.3, ruby_platform: x86_64-darwin10.7.4
********************************************************************************
user system total real
Date.today 0.620000 0.000000 0.620000 ( 0.625817)
Date.new 0.410000 0.000000 0.410000 ( 0.406781)
@modsognir
Copy link

Here's an interesting output. 1.9.2dev was twice as fast as release 1.9.2.

patchlevel: 0, release_date: 2010-08-18, ruby_version: 1.9.2, ruby_platform: x86_64-darwin10.7.0


            user     system      total        real

Date.today 9.520000 0.030000 9.550000 ( 9.743164)
Date.new 9.130000 0.020000 9.150000 ( 9.197950)

patchlevel: 180, release_date: 2011-02-18, ruby_version: 1.9.2, ruby_platform: x86_64-darwin10.7.0


            user     system      total        real

Date.today 9.550000 0.030000 9.580000 ( 9.686037)
Date.new 9.030000 0.020000 9.050000 ( 9.174048)

patchlevel: -1, release_date: 2010-07-11, ruby_version: 1.9.2, ruby_platform: x86_64-darwin10.4.0


            user     system      total        real

Date.today 4.970000 0.010000 4.980000 ( 5.095082)
Date.new 4.010000 0.020000 4.030000 ( 4.066821)

patchlevel: -1, release_date: 2011-07-31, ruby_version: 1.9.3, ruby_platform: x86_64-darwin11.0.0


             user     system      total        real

Date.today 1.180000 0.010000 1.190000 ( 1.206910)
Date.new 1.370000 0.000000 1.370000 ( 1.400995)

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