Skip to content

Instantly share code, notes, and snippets.

@hardboiled
Last active August 29, 2015 14:18
Show Gist options
  • Save hardboiled/6f365c40985e8f1c112d to your computer and use it in GitHub Desktop.
Save hardboiled/6f365c40985e8f1c112d to your computer and use it in GitHub Desktop.
Profile a code block
# 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