tshm
3/2/2016 - 8:02 AM

web performance

web performance

# network connection test script.

$url = "http://www.google.com/"
$sleep = 1

function test() {
  try {
    $meas = Measure-Command {
      $response = Invoke-WebRequest $url
    }
    $time = [Math]::Round($meas.TotalMilliseconds)
    if (-not $response.statuscode -eq 200) { $time = -1 }
  } catch {
    $time = -1
  }
  return $time
}

while(1) {
  $clock = (Get-Date).ToString()
  $time = test
  $mes = "$clock`t$time"
  Write-Output $mes
  [Console]::Error.WriteLine($mes)
  Start-Sleep -Seconds $sleep
}