what are the equivalent java api s that I should be using for the following C# code please? What i need is to check the response time.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
System.Diagnostics.Stopwatch timer = new Stopwatch();
timer.Start();
Ht开发者_开发技巧tpWebResponse response = (HttpWebResponse)request.GetResponse();
timer.Stop();
TimeSpan timeTaken = timer.Elapsed;
Thanks in advance.
Try:
long start = System.currentTimeMillis();
//doSth.
long elapsed = System.currentTimeMillis() - start;
For more precision you could use System.nanoTime()
which returns the nano seconds between two calls. Just note this: This method provides nanosecond precision, but not necessarily nanosecond accuracy.
A simple way to read from an URL and measure the speed might be:
long start = System.currentTimeMillis();
URL url = new URL(urlString);
url.getContent();
long elapsed = System.currentTimeMillis() - start;
look for an HttpURLConnection example like this one.
Then use System.nanotime()
to benchmark it
精彩评论