Quick actions

cmd+k|ctrl+k

Navigation

Languages

js 执行时间测试

Snippet info

Language

JavaScript

Visibility

public

Author

dugujianxiao

Created

2015-11-26T09:10:39Z

Updated

2015-11-26T09:10:39Z

function add(){
    var sum = 0 ;
    function fun_test (a,b){
        return a+b;
    }
    for(var i = 0;i<9000000;i++){
        sum += i;

        fun_test(1,2);
    }
return sum;
}

function test(func){
    var start = new Date().getTime();//起始时间
    func();//执行待测函数
    var end = new Date().getTime();//接受时间
    return (end - start)+"ms";//返回函数执行需要时间
}

var time = test(add);

console.log(time);
INFO