开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜