Benchmarking your code

If you’re going on server side, you need to pay attention to bottlenecks. Especially when you’re paying by the clock.

Lets learn about yield:

def benchmark

  beginning_time = Time.now

  yield #what’s this?

  end_time = Time.now

  puts “Time elapsed: #{(end_time - beginning_time)}s”

end

#Execute

benchmark {(1..10000).each { |i| i*i }}