java – 如何使用System.currentTimeMillis()以秒为单位测量时间跨度?
作者:互联网
如何转换System.currentTimeMillis();几秒钟?
long start6=System.currentTimeMillis();
System.out.println(counter.countPrimes(100000000)+" for "+start6);
控制台向我展示了用于1307816001290的5761455.
我看不出多少秒.
有帮助吗?
解决方法:
long start = System.currentTimeMillis();
counter.countPrimes(1000000);
long end = System.currentTimeMillis();
System.out.println("Took : " + ((end - start) / 1000));
UPDATE
更准确的解决方案是:
final long start = System.nanoTime();
counter.countPrimes(1000000);
final long end = System.nanoTime();
System.out.println("Took: " + ((end - start) / 1000000) + "ms");
System.out.println("Took: " + (end - start)/ 1000000000 + " seconds");
标签:java,milliseconds 来源: https://codeday.me/bug/20190928/1826579.html