I am writing a script to get TTFB for an URL. This getResponseCode method gives me status code for the URL. What method or formula can I use to get TTFB after connection is established?
HttpURLConnection connection
try {
URL url = new URL('www.xyx.com')
connection = (HttpURLConnection)url.openConnection()
connection.setRequestMethod("GET")
connection.connect()
println(connection.getResponseCode())
}
catch(Exception ex) {
return 0
}
finally {
connection.disconnect()
}
The obvious way
However I'm not sure about accuracy...