Skip to content

Instantly share code, notes, and snippets.

@warmwaffles
Created June 4, 2014 22:27
Show Gist options
  • Save warmwaffles/8027ea685c1d67d97046 to your computer and use it in GitHub Desktop.
Save warmwaffles/8027ea685c1d67d97046 to your computer and use it in GitHub Desktop.
Benchmark of the ruby Time class.
require 'time'
require 'benchmark'
max = (ARGV.shift || 100000).to_i
puts "# of iterations = #{max}"
Benchmark::bm(20) do |x|
x.report("Time.parse") do
(0..max).each do
Time.parse("2010-08-15 00:00:00 UTC").to_i
end
end
x.report("Time.utc") do
(0..max).each do
Time.utc(2010, 8, 15).to_i
end
end
end
@warmwaffles
Copy link
Author

On a Core i7

# of iterations = 100000
                          user     system      total        real
Time.parse            9.140000   0.010000   9.150000 (  9.161342)
Time.utc              0.310000   0.000000   0.310000 (  0.311067)

@warmwaffles
Copy link
Author

On an Arm7

# of iterations = 100000
                           user     system      total        real
Time.parse            45.760000   4.230000  49.990000 ( 50.027684)
Time.utc               3.440000   2.720000   6.160000 (  6.157313)

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