Created
October 19, 2010 20:10
-
-
Save bspaulding/635001 to your computer and use it in GitHub Desktop.
A simple task timing class. It allows you to time the execution of any inline block or proc.
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
# BSTimer | |
# - A simple task timing class. It allows you to time the execution of any inline block or proc. | |
# Author: Bradley J. Spaulding | |
# Created On: 2010-10-11 | |
# Last Updated: 2010-10-19 | |
# | |
class BSTimer | |
def self.time(num_trials = 1, &block) | |
results = [] | |
num_trials.times do | |
start_time = Time.now | |
block.call | |
end_time = Time.now | |
results << (end_time - start_time) | |
end | |
results.each_with_index {|result, index| puts "#{index+1}) #{result}" } | |
puts "Mean: #{results.sum/results.size}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment