正确的计算耗时

package test001;

public class test01 {
    public static void main(String[] args) throws InterruptedException {
        for(int i=0;i<20;i++){
            test();
        }
    }
    private static void test() throws InterruptedException{
        long nano=System.nanoTime();
        long millis=System.currentTimeMillis();
       
        Thread.sleep(2);
       
        System.out.println((double)(System.nanoTime()-nano)/1000000);
        System.out.println((System.currentTimeMillis()-millis));
        System.out.println("----------------------------------");
    }

}

posted @ 2014-07-17 13:25  塔斯曼  阅读(231)  评论(0编辑  收藏  举报