不清楚idea是否可以设置运行程序后直接显示时间
但可以代码包含进行测试:
//毫秒ms:
long startTime=System.currentTimeMillis(); //获取开始时间
//要测的程序或方法
long endTime=System.currentTimeMillis(); //获取结束时间
System.out.println("程序运行时间: "+(endTime-startTime)+"ms");
//纳秒ns:
long startTime=System.nanoTime(); //获取开始时间
//要测的程序或方法
long endTime=System.nanoTime(); //获取结束时间
System.out.println("程序运行时间: "+(endTime-startTime)+"ns");
//微秒μs:
long startTime=System.currentTimeMillis()*1000; //获取开始时间
//要测的程序或方法
long endTime=System.currentTimeMillis()*1000; //获取结束时间
System.out.println("程序运行时间: "+(endTime-startTime)+"μs");