开发者

Equivalent java code to measure response time of server

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜