js如何查看一个函数的执行时间

定义一个测试函数,将待测函数作为参数传入

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

猜你喜欢

转载自blog.csdn.net/qq_25983579/article/details/109637025