Java如何测试两个程序之间运行耗时呢?
下文笔者讲述使用java代码检测两个程序之间运行耗时的方法及示例分享,如下所示
我们只需在程序开始计时前面和结尾 加入 System.nanoTime() 此时此种方式,即可获取程序的运行耗时例:程序运行耗时的示例
public static void main(String[] args) throws InterruptedException { long a = System.nanoTime(); Thread.sleep(2000); long b = System.nanoTime(); System.out.println(a); System.out.println(b); }
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。