Skip to content

Instantly share code, notes, and snippets.

@chingsley
Created January 7, 2022 21:33
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 chingsley/d10b84352a401f3c5c6f799e5c9b87c7 to your computer and use it in GitHub Desktop.
Save chingsley/d10b84352a401f3c5c6f799e5c9b87c7 to your computer and use it in GitHub Desktop.
benchmarking with blocks in ruby
def benchmark(&block)
start_time = Time.now
block.call
end_time = Time.now
return end_time - start_time
end
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