Skip to content

Instantly share code, notes, and snippets.

@yclim95
Forked from nextacademy-private/block_benchmark.rb
Created January 12, 2016 15:13
Show Gist options
  • Save yclim95/50ddb1ff5bfd9fc187e5 to your computer and use it in GitHub Desktop.
Save yclim95/50ddb1ff5bfd9fc187e5 to your computer and use it in GitHub Desktop.
def benchmark
# Your benchmarking code goes here.
start_time=Time.now
yield # yield (long_string.reverse) ==> execute command in {}
end_time=Time.now
end_time-start_time #return back to running_time below
end
# Be careful, pasting this into IRB will take a long time to print.
# It's a loooong string. :)
long_string = "apple"*100000000
running_time = benchmark { long_string.reverse }
puts "string.reverse took #{running_time} seconds to run"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment