How to measure client side page load time?



  • I need to measure response time for a website.

    1. Response time to open a page of a web site: I mean the loading time, some way to see the difference in time before and after open a website page.

      But this way, measuring the client loading time, will depend on the client used client. What is the best way to measure that?

      long startTime = System.currentTimeMillis();
      
      driver.get("http://zyxware.com");
      new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.id("Calculate")));
      
      long endTime = System.currentTimeMillis();
      long totalTime = endTime - startTime;
      
      System.out.println("Total Page Load Time: " + totalTime + "milliseconds");
      

    or this?

    driver.get("url");
            WebElement ele = $(By.tagName("body"));
            // get the  page load time
            Long loadtime = (Long)((JavascriptExecutor)driver).executeScript(
                "return performance.timing.loadEventEnd - performance.timing.navigationStart;");        
            System.out.println(loadtime);
    

    and last way the following:

    StopWatch pageLoad = new StopWatch();
                pageLoad.start();
                //Open your web app (In my case, I opened facebook)
                driver.get("url");
                // Wait for the required any element (I am waiting for Login button in fb)
                WebDriverWait wait = new WebDriverWait(driver, 10);
                wait.until(ExpectedConditions.presenceOfElementLocated(By.tagName("body")));
    
                pageLoad.stop();
                //Get the time
                long pageLoadTime_ms = pageLoad.getTime();
                long pageLoadTime_Seconds = pageLoadTime_ms / 1000;
                System.out.println("Total Page Load Time: " + pageLoadTime_ms + " milliseconds");
    
    1. if I have a search button for the same website, if I need to measure the search time, how to do it? is it as same as the above way?


  • Selenium is the wrong tool for measuring page load times. Selenium can't actually block until the page finishes loading, so it has to poll the browser. Your load time precision is constrained by the poll interval.

    The most accurate tools for measuring page load times are browser extensions like YSlow, Firebug, and the Chrome DevTools.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 3
  • 2