Skip to content

Instantly share code, notes, and snippets.

@Fluxx
Created July 31, 2011 19:50
Show Gist options
  • Select an option

  • Save Fluxx/1117138 to your computer and use it in GitHub Desktop.

Select an option

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)
@huacnlee
Copy link
Copy Markdown

huacnlee commented Aug 2, 2011

ruby_version: ree-1.8.7-2011.03, ruby_platform: i686-darwin10.7.0


            user     system      total        real

Date.today 9.840000 0.470000 10.310000 ( 10.318659)
Date.new 12.830000 0.370000 13.200000 ( 13.235627)

ruby_version: ruby-1.8.7-p334, ruby_platform: i686-darwin10.7.0


            user     system      total        real

Date.today 12.520000 0.150000 12.670000 ( 12.685077)
Date.new 16.980000 0.200000 17.180000 ( 17.296614)

ruby_version: ruby-1.9.2-p180, ruby_platform: x86_64-darwin10.7.0


            user     system      total        real

Date.today 3.820000 0.030000 3.850000 ( 3.857992)
Date.new 3.420000 0.020000 3.440000 ( 3.433169)

ruby_version: ruby-1.9.2-p290, ruby_platform: x86_64-darwin10.8.0


            user     system      total        real

Date.today 3.970000 0.090000 4.060000 ( 4.059857)
Date.new 3.430000 0.070000 3.500000 ( 3.494904)

malloc_limit=50000000 (8000000)
heap_min_slots=500000 (10000)
ruby_version: ruby-1.9.3-preview1, ruby_platform: x86_64-darwin10.8.0


             user     system      total        real

Date.today 0.590000 0.010000 0.600000 ( 0.598072)
Date.new 0.470000 0.020000 0.490000 ( 0.482155)

@huacnlee
Copy link
Copy Markdown

huacnlee commented Aug 2, 2011

The pathname and date libraries were reimplemented in C, primarily for performance reasons.

Copy link
Copy Markdown

ghost commented Aug 2, 2011

Operating System: Apple Mac OS X Lion
Compiler System: Apple Xcode Version 4.1 (4B110)
Computer System: 2011 15" Quad Intel Core i7 2.3GHz + 8GB 1333MHz RAM Macbook Pro
Drive: Hitachi 7200RPM 500.11GB SATA-II
RVM: v1.6.32

∴ rvm ruby bin/date_test.rb
patchlevel: 174, release_date: yyyy-mm-dd, ruby_version: 1.8.7, ruby_platform: x86_64-apple-darwin11.0.0


            user     system      total        real

Date.today 4.945836 0.021708 4.967544 ( 4.754525)
Date.new 7.907944 0.009149 7.917093 ( 7.835825)

patchlevel: 352, release_date: 2011-06-30, ruby_version: 1.8.7, ruby_platform: i686-darwin11.0.0


            user     system      total        real

Date.today 8.550000 0.010000 8.560000 ( 8.556778)
Date.new 11.380000 0.010000 11.390000 ( 11.380812)

patchlevel: 136, release_date: 2010-12-25, ruby_version: 1.9.2, ruby_platform: x86_64-darwin11.0.0


            user     system      total        real

Date.today 2.680000 0.010000 2.690000 ( 2.688886)
Date.new 2.250000 0.010000 2.260000 ( 2.259816)

patchlevel: 290, release_date: 2011-07-09, ruby_version: 1.9.2, ruby_platform: x86_64-darwin11.0.0


            user     system      total        real

Date.today 2.700000 0.010000 2.710000 ( 2.701262)
Date.new 2.430000 0.000000 2.430000 ( 2.436612)

patchlevel: -1, release_date: 2011-08-02, ruby_version: 1.9.3, ruby_platform: x86_64-darwin11.0.0


             user     system      total        real

Date.today 0.460000 0.000000 0.460000 ( 0.461122)
Date.new 0.320000 0.000000 0.320000 ( 0.320850)

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


             user     system      total        real

Date.today 0.500000 0.000000 0.500000 ( 0.505935)
Date.new 0.340000 0.000000 0.340000 ( 0.335285)

@modsognir
Copy link
Copy Markdown

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