Skip to content

Instantly share code, notes, and snippets.

@SP3269
Last active June 14, 2023 05:41
Show Gist options
  • Save SP3269/78ee1b749a80c5421c350fa62fdb1804 to your computer and use it in GitHub Desktop.
Save SP3269/78ee1b749a80c5421c350fa62fdb1804 to your computer and use it in GitHub Desktop.
# Using curl to measure TLS negotiation time, as a proxy of PKCS #11 performance
# https://blog.cloudflare.com/a-question-of-timing/
function Get-ConnectionTimes ([string] $Uri) {
$curl = curl -w "%{time_namelookup},%{time_connect},%{time_appconnect}\n" -s -o /dev/null $Uri
$namelookup,$connect,$appconnect = $curl -split ","
$res = [PSCustomObject]@{
namelookup = [float]$namelookup
connect = [float]$connect
appconnect = [float]$appconnect
}
return $res
}
function Get-TLSHandshakeTime ([string] $Uri) {
$res = Get-ConnectionTimes $Uri
return $res.appconnect - $res.connect
}
# Example
1..20 | % {Get-ConnectionTimes "https://www.googleapis.com"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment