I need to know time to load a webpage from internet. I do not need to show the page and definitely discard contents after it loads. So I am using this:
suspend fun TimeItTook(): Long {
val startTime: Long = System.currentTimeMillis()
var endTime: Long = 0
// Instantiate the RequestQueue.
val queue = Volley.newRequestQueue(mContext)
val url = "https://www.google.com"
// Request a string response from the provided URL.
val stringRequest = StringRequest(
Request.Method.GET, url,
{ response ->
endTime = System.currentTimeMillis() //It should get the time when response arrives
//print(response)
},
{ endTime = startTime }) //if fails result should be 0
// Add the request to the RequestQueue.
queue.add(stringRequest)
return endTime - startTime
}
Now the result is negative. Which means there is something wrong.
And also I need to know if there is a better way to know the time required to load a web page.