Skip to content

Instantly share code, notes, and snippets.

@Ebonkuab
Created January 7, 2016 19:21
Show Gist options
  • Save Ebonkuab/02a5e647a982e7a3aa93 to your computer and use it in GitHub Desktop.
Save Ebonkuab/02a5e647a982e7a3aa93 to your computer and use it in GitHub Desktop.
code for getting how long it takes to run a programme written in Ruby using Yield keyword and blocks . (LIGHTHOUSE WEB DEV BOOTCAMP0
def benchmark
# Your benchmarking code goes here.
start_time = Time.now
yield
end_time = Time.now
running_time = end_time - start_time
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