1

私のアプリでは、次のように外部サーバーに複数のリクエストを行いますか?

    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
4

1 に答える 1

3

Rubyのベンチマークモジュールは次のように使用できます。

time = Benchmark.realtime do
      req.perform
end
puts "Time elapsed #{time*1000} milliseconds"
于 2013-01-09T13:00:44.057 に答える