查看程序运行时间

long begin = System.currentTimeMillis();
。。。。。 // 你的代码

long end = System.currentTimeMillis();

System.out.println(end-begin); // 结果为毫秒,1秒=1000毫秒


完整的代码
/*
* @(#)Timing.java
*/
package ds.time;

/**
* An instance of the class acts like a stop watch for measuring the
* time required to execute a process; time is measured in seconds from start to stop
* using millisecond intervals from the system clock.
*/
public class Timing
{
// starting and ending time measured in milliseconds
private long startTime, stopTime;

/**
* Creates an instance with default values 0 for both the start time and
* and the stop time.
*/
public Timing()
{
startTime = stopTime = 0;
}

/**
* Establishes a starting time for the process by recording the
* current millisecond time on the system clock
*/
public void start()
{
startTime = System.currentTimeMillis();
}

/**
* Establishes a time in seconds by computing the interval from the start time
* to the current time on the system clock.
* @return interval of time from start to stop measured in seconds.
*/
public double stop()
{
stopTime = System.currentTimeMillis();

return (stopTime - startTime)/1000.0;
}
}


function Timing() {
this.startTime = null;
this.stopTime = null;

Timing.prototype.start = function(){
this.startTime = new Date();
};

Timing.prototype.stop = function() {
this.stopTime = new Date();
return (this.stopTime.getTime() - this.startTime.getTime()) + 'ms';
};
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值