Created
October 26, 2012 00:10
-
-
Save dladowitz/3956253 to your computer and use it in GitHub Desktop.
Testing timers using Benchmark vs start/end/ diffing
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
require 'benchmark' | |
def janky(length) | |
start_time = Time.now | |
(1..length).each { |num| num } | |
time = Time.now - start_time | |
time | |
end | |
def benchmarked(length) | |
time = Benchmark.realtime do | |
(1..length).each { |num| num } | |
end | |
time | |
end | |
puts "janky version time: #{janky(4000)}" | |
puts "benchmarked version time: #{benchmarked(4000)}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These two methods apparently aren't the same.
ladowitzs-mbair:Desktop dladowitz$ ruby times.rb
janky version time: 0.000471
benchmarked version time: 0.000594