RTRT。。
授之以鱼不如授渔。。也教教我怎么查吧。。
授之以鱼不如授渔。。也教教我怎么查吧。。
解决方案 »
- 需要7m,11m,17m的管子各10根,至少需要多少根100m的管子,并求出每根管子的利用率
- 正则问题
- 新手在线等待解答,关于用java编写浏览器问题
- 关于Hibernate的Session和SessionFactory
- 如何从java.sql.Date 转换到 java.util.Date????
- 做JList时能编译但运行报空指向,请教各位大哥们
- ——————120分求一个问题!!!
- 一个小问题,困扰着我~
- 怎么样用java写一个程序,把.dbf的文件转成mysql的文件?急!!!
- 子类继承父类的方法和变量后,子类中是不是存在父类的方法和变量?
- 关于java的包
- 来帮个忙 重谢!关于JAVA
在程序结束的地方得到一次时间,两个时间相减,就是程序运行的毫秒数。
public static void main(String[] args){
String str="";
long startTime=System.currentTimeMillis();//开始计时
//这里得到的时间是一个long型的毫秒数,具体是怎么样一个毫秒数去查API中的System的这个方法
for(int i=0;i<1000;i++){
str=str+1;
}
long endTime=System.currentTimeMillis();//结束获取结束时的时间
long runTime=endTime-startTime;//两个时间只差就是运行时间
System.out.print("程序运行时间是:"+runTime+"毫秒");
}
}
Clock clock = Clock.getNanoSecondClock();
clock.start();
for(int i = 0; i < 10000; i++);
clock.stop();
System.out.println(clock.spendTime());
}
}/**
* 用于测量代码执行的计时器
*/
public abstract class Clock { private long start;
private long end; private Clock() { } private final static Clock MILLIS_SECOND_CLOCK = new Clock() {
protected long getCurrentTime() {
return System.currentTimeMillis();
}
}; private final static Clock NANO_SECOND_CLOCK = new Clock() {
protected long getCurrentTime() {
return System.nanoTime();
}
}; /**
* 获得毫秒级别的计时器
* @return
*/
public static Clock getMillisSecondClock() {
return MILLIS_SECOND_CLOCK;
} /**
* 获得纳秒级别的计时器
* @return
*/
public static Clock getNanoSecondClock() {
return NANO_SECOND_CLOCK;
} /**
* 获得耗时
* @return
*/
public long spendTime() {
if(end == 0L) {
stop();
}
long spend = end - start;
start = end = 0L;
return spend;
} /**
* 启动计时器
*/
public void start() {
start = getCurrentTime();
} /**
* 停止计时器
*/
public void stop() {
end = getCurrentTime();
} /**
* 获得当前计时器的时间
* @return
*/
protected abstract long getCurrentTime();
}
* 获得耗时
* @return
*/
public long spendTime() {
if(end == 0L) {
stop();
}
return (end - start);
} /**
* 启动计时器
*/
public void start() {
end = 0L;
start = getCurrentTime();
}