Skip to content

Instantly share code, notes, and snippets.

@Leejojo
Created June 24, 2016 23:19
Show Gist options
  • Select an option

  • Save Leejojo/4810cc4cbb02656fcbb08fa130e81397 to your computer and use it in GitHub Desktop.

Select an option

Save Leejojo/4810cc4cbb02656fcbb08fa130e81397 to your computer and use it in GitHub Desktop.
Benchmark with Blocks
def benchmark
# Your benchmarking code goes here.
start_time = Time.now
yield
end_time = Time.now
puts @duration = 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
benchmark { long_string.reverse }
puts "string.reverse took #{@duration} seconds to run"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment