Skip to content

Instantly share code, notes, and snippets.

@zimbatm
Created May 16, 2014 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zimbatm/f487e466f7932ed2b3b7 to your computer and use it in GitHub Desktop.
Save zimbatm/f487e466f7932ed2b3b7 to your computer and use it in GitHub Desktop.
Time benchmark
# gem install benchmark-ips
require 'benchmark/ips'
class << Time
attr_accessor :current
end
Time.current = Time.now
Benchmark.ips do |x|
x.report("Time.now") do |n|
n.times do
Time.now
end
end
x.report("Time.current") do |n|
n.times do
Time.current
end
end
end
Calculating -------------------------------------
Time.now 77329 i/100ms
Time.current 111682 i/100ms
-------------------------------------------------
Time.now 2232278.9 (±4.2%) i/s - 11212705 in 5.032705s
Time.current 13550961.4 (±7.1%) i/s - 67344246 in 5.003133s
ruby bm.rb 14.02s user 0.06s system 99% cpu 14.107 total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment