2012-12-04 49 views
2

我搜索了一遍,通过SO进行搜索,并通过主机page上推荐的导航时间页面进行了阅读,但无法自行解决。watir-webdriver-performance gem中的response_time,:time_to_first_byte和time_to_last_byte有什么区别?

:response_time:time_to_first_byte:time_to_last_byte有什么区别?

从我的理解,以及在导航计时文档,似乎:response_time应该是:time_to_first_byte的总和,:time_to_last_byte,但是在执行我的测试中,我发现事实并非如此。

require 'watir-webdriver-performance' 

    $response = $browser.performance.summary[:response_time] 
    $first_byte = $browser.performance.summary[:time_to_first_byte] 
    $last_byte = $browser.performance.summary[:time_to_last_byte] 

    def performance_check 
     puts ("#{$browser.url}: Response time: #{$response}ms.") 

     puts ("#{$browser.url}: Time to first byte: #{$first_byte}ms.") 

     puts ("#{$browser.url}: Time to last byte: #{$last_byte}ms.") 
    end 

    def test_site_01 
     $browser.goto("http://www.google.com/") 
     performance_check 
    end 

我看到的典型输出是:

http://www.google.com: Response time: 1558ms. 
    http://www.google.com: Time to first byte: 384ms. 
    http://www.google.com: Time to last byte: 385ms. 

谢谢。

回答

5

第一个字节的时间(TTFB)是服务器返回响应中第一个字节的信息的时间。所以TTFB在这块宝石相当于:

response_start - domain_lookup_start if domain_lookup_start > 0

,并将包括DNS,连接和请求开销。

时间在这颗宝石最后一个字节(TTLB)等同于:

response_end - domain_lookup_start

所以应包括DNS,连接,要求&响应开销。

所以在你的例子中,TTFB和TTLB之间只需要1ms就可以有效地传输内容。摘要中的响应时间是散列中所有度量的最早和最新时间​​戳之间的增量。所以实际上navigation_start和load_end之间的所有内容。

这包括规范中提供的所有DNS,TCP,连接,请求,响应和浏览器处理/加载时序。

在你的代码,如果你只是转储哈希

$browser.performance.summary

,你应该能够看到所有的相关指标。

+0

非常感谢你:) – Mellissa