Skip to content

Instantly share code, notes, and snippets.

@bradland
Created November 9, 2011 20:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bradland/1352997 to your computer and use it in GitHub Desktop.
Save bradland/1352997 to your computer and use it in GitHub Desktop.
Date bench
#!/usr/bin/env ruby
require 'benchmark'
require 'date'
Benchmark.bm do|b|
ITERATE = 100000
b.report("strptime") do
time = "2011-05-25 00:00:03 -0400"
fmt = "%Y-%m-%d %H:%M:%S %z"
ITERATE.times { DateTime.strptime(time, fmt) }
end
b.report("parse") do
time = "2011-05-25 00:00:03 -0400"
ITERATE.times { DateTime.parse(time) }
end
end
@bradland
Copy link
Author

My results with various versions of Ruby:

ruby-1.9.3-p125
               user     system      total        real
strptime   1.080000   0.000000   1.080000 (  1.077532)
parse      3.080000   0.000000   3.080000 (  3.098193)

ruby-1.9.2-p290
              user     system      total        real
strptime 23.150000   0.130000  23.280000 ( 23.795165)
parse    16.440000   0.120000  16.560000 ( 16.777957)

ree-1.8.7-2011.03
              user     system      total        real
strptime 34.350000   0.110000  34.460000 ( 34.690829)
parse    24.850000   0.100000  24.950000 ( 25.036774)

ruby-1.8.7-p352
              user     system      total        real
strptime 40.070000   0.140000  40.210000 ( 40.818735)
parse    28.990000   0.110000  29.100000 ( 29.181162)

@bradland
Copy link
Author

Tried today with Rubinius:

 rubinius 2.0.0dev (1.8.7 95332ce8 yyyy-mm-dd JI) [x86_64-apple-darwin11.3.0]
              user     system      total        real
strptime 54.952456   0.181634  55.134090 ( 53.420454)
parse    34.012551   0.081722  34.094273 ( 33.583420)

@bradland
Copy link
Author

Aaaand one with JRuby:

jruby 1.6.6 (ruby-1.8.7-p357) (2012-01-30 5673572) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]
              user     system      total        real
strptime 22.628000   0.000000  22.628000 ( 22.589000)
parse    15.086000   0.000000  15.086000 ( 15.086000)

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