http://www.moon4chen.com/

Java 时间测量、耗时计算方法

System.currentTimeMillis

精准度:ms

返回:当前时间与1970年1月1日之间的毫秒差

优缺:

`精度和准确度可能不够

`更改系统时间会影响结果

     long start = System.currentTimeMillis();
        //do something
        long end = System.currentTimeMillis();

System.nanoTime

精准度:ns

返回:当前系统(程序)计时器的精确值(ns)

优缺:

`没有定义参考时间,只能用来测量时间间隔

     long start = System.nanoTime();
        //do something
        long end = System.nanoTime();

更多:

Debug.threadCpuTimeNanos

SystemClock.currentThreadTimeMills

SystemClock.elapsedRealTime

SystemClock.upTimeMills

 

posted @ 2015-06-23 22:28  谌皓徽  阅读(1772)  评论(0编辑  收藏  举报