English 中文(简体)
Watir - Page Performance
  • 时间:2024-03-18 23:00:37

Watir - Page Performance


Previous Page Next Page  

Watir页的性能特征使你能够跟踪反应时间尺度,并在 Chrome、IE9及以上进行微调。 至今,Safaribrowser没有获得支持。

让我们更仔细地研究如何利用这一特点。 为了加以利用,我们需要使用下文所示的gem安装轮胎性能。

Command

gem install watir-performance
Watir Performance

我们安装了轮胎性能。 支持的指标是:

    summary

    navigation

    memory

    Timing

此处讨论了使用高射电效应的工作实例。 在此,我们将检查网站的回复时间——www.tutorialspoint.com。 如下所示:

require  watir 
require  watir-performance 
10.times do
   b = Watir::Browser.new :chrome
   b.goto  https://www.tutorialspoint.com 
   load_secs = b.performance.summary[:response_time] / 1000
   puts "Load Time: #{load_secs} seconds."
   b.close
end

output

Load Time: 7 seconds.
Load Time: 7 seconds.
Load Time: 5 seconds.
Load Time: 5 seconds.
Load Time: 6 seconds.
Load Time: 5 seconds.
Load Time: 5 seconds.
Load Time: 13 seconds.
Load Time: 12 seconds.
Load Time: 5 seconds.

Using performance.timing

require  watir 
require  watir-performance 

b = Watir::Browser.new :chrome
b.goto  https://www.tutorialspoint.com 
load_secs = b.performance.timing[:response_end] - b.performance.timing[:response_start]
puts "Time taken to respond is #{load_secs} seconds."
b.close

output

Time taken to respond is 41 seconds.

Using performance.navigation

require  watir 
require  watir-performance 

b = Watir::Browser.new :chrome
b.goto  https://www.tutorialspoint.com 
perf_nav = b.performance.navigation
puts "#{perf_nav}"
b.close

output

{:type_back_forward=>2, :type_navigate=>0, :type_reload=>1, 
:type_reserved=>255, :redirect_count=>0, :to_json=>{}, :type=>0}

Using performance.memory

require  watir 
require  watir-performance 

b = Watir::Browser.new :chrome
b.goto  https://www.tutorialspoint.com 
memory_used = b.performance.memory
puts "#{memory_used}"
b.close

output

{:js_heap_size_pmit=>2, :type_navigate=>0, :type_reload=>1, :ty2136997888, 
:total_js_heap_size=>2, :type_navigate=>0, :type_reload=>1, :ty12990756, 
:used_js_heap_size=>2, :type_navigate=>0, :type_reload=>1, :ty7127092}
Advertisements