开发者

Java: What is the unit of the difference of two System.currentTimeMillis?

What is the unit of the difference of two System.currentTimeMillis ?

start = System.currentTimeMillis();
longoperation();
elapsedTime = System.currentTimeMillis() - start;

What is the unit of elapsed time here. It doesn't look like milliseconds. Is the above code segment the right way to find the t开发者_运维知识库ime taken to execute longoperation()?


Yes, it is in milliseconds. Bear in mind that the difference is not absolutely correct and may vary.


It is ms (MiliSecond) only, you are doing right.
You can ignore time taken while calculating millis


It is milliseconds and your code looks correct.


Whatever you are doing is correct. If you want the time in seconds, simply divide it by 1000.

long start = System.currentTimeMillis();
longoperation();
long elapsedTime = (System.currentTimeMillis() - start)/1000;


Yes, currentTimeMillis() returns you a milliseconds value.

On Windows, it used to be the case that the returned value had quite low resolution, and so was only accurate to something like 10ms. I'm not certain whether this is still the case as I haven't used Windows for a few years - but if your longoperation() actually takes just a few millis, and you're running on Windows, then you may see elapsedTime variously being 10ms or 0ms.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜