当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Get page load time, X times

问题描述:

I am doing a research about the speed of multiple Javascript charting libraries. I made some testpages, 4 graphs each with libraries such as Highcharts, Flot, D3, AmCharts, FusionCharts etc.

Now I want run each page 100 times to get their individual loading speed and average for each library. I am actually not even sure if this is even possible.

I thought about doing the following:

  1. Load the page with the graphs with CURL (PHP)

    function getContents($url) {

    $ch = curl_init();

    $header = array(

    'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12',

    'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',

    'Accept-Language: en-us,en;q=0.5',

    'Accept-Encoding: gzip,deflate',

    'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',

    'Keep-Alive: 115',

    'Connection: keep-alive',

    );

    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

    $result = curl_exec($ch);

    curl_close($ch);

    }

  2. On the page itself, capture loading time with Javascript and write that to a file in PHP.

    var loadTime = window.performance.timing.domContentLoadedEventEnd - window.performance.timing.navigationStart;

    $.ajax({

    type: "POST",

    url: "SaveTime.php",

    data: {action: "saveloadtime", time: loadTime}

    })

    .done(function(msg) {

    });

However, this will run only once and besides that I do not get any result in the file on my server.

  • Is it possible that the Javascript does not get executed while calling the page trough PHP?
  • How do I loop 100 times trough a page: wait until fully loaded, savetime, load next test, etc. ?

I know I can use the Google Chrome console, Firebug or any other plugin, but I do not want to get the speed manually, since I have a lot of pages to compare.

Any help is appreciated

分享给朋友:
您可能感兴趣的文章:
随机阅读: