Skip to content

Instantly share code, notes, and snippets.

@bspaulding
Created October 19, 2010 20:10
Show Gist options
  • Save bspaulding/635001 to your computer and use it in GitHub Desktop.
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.
# 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