Skip to content

Instantly share code, notes, and snippets.

@j0ni
Created May 27, 2016 17:26
Show Gist options
  • Save j0ni/dac2da8df3d7d1b282c8e50dff427510 to your computer and use it in GitHub Desktop.
Save j0ni/dac2da8df3d7d1b282c8e50dff427510 to your computer and use it in GitHub Desktop.
# step 1 - eval apple*x and assign to long_string
long_string = "apple"*100000000
# step 2 - define method benchmark
def benchmark
before = Time.now.to_i
yield # step 4 - evaluate the block
Time.now.to_i - before # step 5 - return the time
end
# step 3 - call benchmark with a block
running_time = benchmark { long_string.reverse } # step 6 - assign value to running_time
puts running_time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment