long startTime = System.currentTimeMillis(); //获取开始时间
doSomething(); //测试的代码段
long endTime = System.currentTimeMillis(); //获取结束时间
System.out.println("程序运行时间:" + (endTime - startTime) + "ms"); //输出程序运行时间
long startTime=System.nanoTime(); //获取开始时间
doSomeThing(); //测试的代码段
long endTime=System.nanoTime(); //获取结束时间
System.out.println("程序运行时间: "+(endTime-startTime)+"ns");
public static void main(String[]args){
String str="";
long starTime=System.currentTimeMillis();
//计算循环10000的时间
for(int i=0;i<10000;i++){
str=str+i;
}
long endTime=System.currentTimeMillis();
long Time=endTime-starTime;
System.out.println(Time);
StringBuilder bulider=new StringBuilder("");
starTime=System.currentTimeMillis();
for(int j=0;j<10000;j++){
bulider.append(j);
}
endTime=System.currentTimeMillis();
Time=endTime-starTime;
System.out.println(Time);
}
public class Main {
/**
* 计算两个时间点直接逝去的毫秒数
*
*/
public void computeAndDisplayElapsedTime() {
long startTime = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
try {
Thread.sleep(60);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
long endTime = System.currentTimeMillis();
float seconds = (endTime - startTime) / 1000F;
System.out.println(Float.toString(seconds) + " seconds.");
}
/**
* 启动程序
*/
public static void main(String[] args) {
new Main().computeAndDisplayElapsedTime();
}
}
```out 0.609 seconds.
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有