I'm trying to understand something about setInterval. When running the
following in FF3, the time it takes to execute the interval's function
does not take longer than the 30ms specified for the interval.
However, it takes longer than 30ms to for the interval to run again.
Where is the extra time going? Is there always some overhead to
running a setInterval? Thanks.
Test = {};
Test.end_repeat = 0;
Test.total = 0;
Test.my_interval = setInterval(function () {
Test.repeat();
}, 30);
Test.repeat = function () {
var t;
Test.start_repeat = new Date().getTime();
if (Test.end_repeat != 0) {
t = Test.start_repeat - Test.end_repeat;
console.log("/////");
console.log("Repeat duration: " + t + "ms");
}
Test.end_repeat = new Date().getTime();
//
Test.action_start = new Date().getTime();
for (var i = 0; i < 35000; i++) { // do something for a while; should
not take longer than 30ms, if so, decrease loop
t = new Date().getTime();
}
t = new Date().getTime() - Test.action_start;
console.log("Action duration: " + t + "ms");
if (Test.total++ > 10) {
clearInterval(Test.my_interval);
}
}
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]