时间戳转换
console.log(times4.toLocaleDateString().replace(/\//g," - ") + ""+times4.toTimeString().substr(0,8));
计算for循环性能和普通函数的对比,普通函数胜出
有for循环
// 输入数字,计算总和
let start = 0;
let end = 0;
start = performance.now();
function sum(n){
let result = 0;
for(var i = 0;i<=n;i++){
result = result+i
}
return result
}
console.log(sum(239))
end = performance.now();
let times = end-start;
console.log(times)
普通函数
let start = 0;
let end = 0;
start = performance.now();
function sum(n){
return (n /2) * (n+1)
}
console.log(sum(239))
end = performance.now();
let times = end-start;
console.log(times)
请自行测试!