在我的应用程序中,我是否像这样向外部服务器发出多个请求:
req = Curl::Easy.new do |curl|
curl.url = "https://www.mysite.com"
curl.headers['Content-type'] = 'application/json'
end
req.perform
是否可以检索响应时间(请求需要多长时间)?
我认为有效的解决方案如下(伪代码),但有更优雅的东西吗?
req = Curl::Easy.new do |curl|
curl.url = "https://www.mysite.com"
curl.headers['Content-type'] = 'application/json'
end
timeBefore = Time.now
req.perform
timeAfter = Time.now
responseTime = timeAfter - timeBefore