Measure and Benchmark Time for Ruby Methods

后端 未结 6 1035
长情又很酷
长情又很酷 2021-01-30 06:04

How can i measure the time taken by a method and the individual statements in that method in Ruby. If you see the below method i want to measure the total time taken by the meth

6条回答
  •  遇见更好的自我
    2021-01-30 06:51

    In the spirit of wquist's answer, but a little simpler, you could also do it like below:

    start = Time.now
    # code to time
    Time.now - start
    

提交回复
热议问题