Last active
August 29, 2015 14:18
-
-
Save hardboiled/6f365c40985e8f1c112d to your computer and use it in GitHub Desktop.
Profile a code block
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
# returns number of seconds elapsed on average for block execution | |
def profile(num_times, idx, &block) | |
profile_arr = [] | |
num_times.times do | |
beginning = Time.now | |
block.call(idx) | |
idx+=1 | |
profile_arr << Time.now - beginning | |
end | |
profile_arr.reduce(:+).to_f / profile_arr.size | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment