HTML规范定义,setTimeout和setInterval的最小间隔是4ms.
举例说明:
var count = 0;
var start = new Date();
var timer = setInterval(function() {
if (new Date() - start > 1000) {
clearInterval(timer);
console.log(count);
return;
}
count++;
}, 0);chrome 35.0 运行结果:250
var count = 0;
var start = new Date();
while(new Date() - start < 1000) {
count++;
}
console.log(count);chrome 35.0 运行结果:725926