Created
May 16, 2014 22:10
-
-
Save zimbatm/f487e466f7932ed2b3b7 to your computer and use it in GitHub Desktop.
Time benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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