FromTheField

Real world experiences of SharePoint CSS engineers from Microsoft UK

Using PowerShell to Measure Page Download Time

Using PowerShell to Measure Page Download Time

  • Comments 11
  • Likes

I was recently working with a customer that reported some performance issues in their SharePoint 2013 proof of concept environment, specifically page render time was very poor. I wanted to establish exactly how bad this was and also put in place some basic automated tests to measure response times over a short period of time. I put together a very quick script that measures how long a specific page takes to download and then repeats the test x number of times, as this only measures page download time it doesn't include any client side rendering therefore it isn't wholly accurate, but is a good starting point for assessing performance.

Below is the script itself, it takes two parameters: -URL, which is the URL of the page to download and -Times, which is the number of times to perform the test. By default the script uses the credentials of the current logged on user to connect to the URL provided.

param($URL, $Times)
$i = 0
While ($i -lt $Times)
{$Request = New-Object System.Net.WebClient
$Request.UseDefaultCredentials = $true
$Start = Get-Date
$PageRequest = $Request.DownloadString($URL)
$TimeTaken = ((Get-Date) - $Start).TotalMilliseconds
$Request.Dispose()
Write-Host Request $i took $TimeTaken ms -ForegroundColor Green
$i ++}

To run the script, copy the commands above into a text editor, save as a .ps1 file and run from a suitable machine. An example of the script in action can be found below.

Brendan Griffin

Comments
  • I can see a geat use for this.  Thanks for positng.

  • Thanks for post.
    Is there a reason/benefit you used 'Net.WebClient' over 'Invoke-WebRequest'?

  • How do we tag this script to every page in SharePoint , so that it logs page response times of every user into a database or a file ?

  • @Sri - this is a PowerShell script that runs client side, you would probably want to look at using a different approach to measure performance at that level. It may be better to use IIS logs or the usage database to record/analyse performance.

  • Is that a correct statement if I say this script will give us Sever Response Time for mentioned site minus "network latency" and minus "end user browser rendering time" ???

  • @Umar - If you want accurate server processing time you really need to parse the IIS log files rather than using this script.

  • I prefer to use the following cmd
    Measure-Command {Invoke-WebRequest http://www.nytimes.com}

  • @Joe Web - That's definitely the way to go now, this script was written to work with PS 2.0 which didn't include that cmdlet.

  • Thank you for this script, it's exactly what I needed.

  • You should probably use the .NET Stopwatch class instead. DateTime is not good for this level of measurement

  • Thanks Paul

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment