gensym has asked for the wisdom of the Perl Monks concerning the following question:

I want to benchmark website load times with WWW::Mechanize::Firefox, but I am getting inconsistent results (from 1 to 7 secs on many samples) benchmarking this call:
$mech->get( $url, no_cache => 1, synchronize => 1 );

When I look at the browser, the page is actually loaded in more or less 1 sec.

Is there a way to get more reliable results?

(I am asking here, because Perlmonks is the official support forum - see WWW::Mechanize::Firefox)

Replies are listed 'Best First'.
Re: How to benchmark with WWW::Mechanize::Firefox?
by LanX (Saint) on Jan 24, 2012 at 16:50 UTC
    Communication through MozRepl is a bottleneck for WWW::Mechanize::Firefox which significantly limits real-time performance.

    If I were you, I would use WMF to inject a JS-Routine to do the website loading and log start and end (needs definition) and calculate the difference.

    Use WMF to poll the logged data from the perl-side.

    Tip: I'm simply setting window.title for that purpose, it gives visual feedback in the window frame and there is a ->title method in WMF to read that field from perl.

    Cheers Rolf

Re: How to benchmark with WWW::Mechanize::Firefox?
by Anonymous Monk on Jan 24, 2012 at 20:34 UTC

    Definitely what lanx said, load a page, that loads js , that creates iframes/ or frames to load stuff, and times it through js

    You can get some ideas/code from http://www.quirksmode.org/dom/innerhtml.html

      > Definitely what lanx said, load a page, that loads js , that creates iframes/ or frames to load stuff, and times it through js

      No frames!!!

      Basically use something like

      $load = $mech->repl->declare(<<'__JS'); function () { // start benchmark window.content.location.href = "http://www.perlmonks.org"; // wait till ready (can be tricky) // stop benchmark // return diff } __JS

      and $load->() should load the page.

      Cheers Rolf