Skip to content

Instantly share code, notes, and snippets.

@Andsbf
Created March 5, 2015 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andsbf/4822844b75444f23fcab to your computer and use it in GitHub Desktop.
Save Andsbf/4822844b75444f23fcab to your computer and use it in GitHub Desktop.
Blocks in Ruby
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"*1000000
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