开发者

In Ruby or Rails, is there a "duration_for { fetch_some_data() }" and it can print "fetch_some_data() done, took 2.1 seconds"?

开发者 https://www.devze.com 2023-02-18 20:18 出处:网络
In Rails, is there already such a function? So that we can use <%= duration_for { fetch_some_data() } %>

In Rails, is there already such a function?

So that we can use

<%= duration_for { fetch_some_data() } %>

and it will print

fetch_some_data() done, result is:
  {"status" : 1, "data" : {"x" : 123} }
(took 2.1 seconds)

Otherwise, what is a good way to write tha开发者_JS百科t in Ruby? (more like a method, so we can't use the UNIX's time to do it)


require 'benchmark'
Benchmark.ms do
  fetch_some_data()
end

will return the time it takes to complete the block in milliseconds.

http://apidock.com/ruby/Benchmark

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号