Jan Swart
Jan Swart

Reputation: 7231

Effect on performance of large setTimeout time

I need to display a notice every hour, or at certain hourly intervals. I was wondering what the effect on performance is of having such a large time out time?

setTimeout(function(){ ... } ,60*60*1000)

The timer doesn't have to be perfect and can be a couple of milliseconds out.

Upvotes: 1

Views: 1315

Answers (2)

Jordumus
Jordumus

Reputation: 2783

setTimeOut() (or setInterval() for that matter) itself is not expensive (performance-wise) at all: after all, it's just a check to see if the determined time has passed.

The "time" you determine doesn't change the performance at all. A setTimeOut(function() {;}, 100); is as expensive as setTimeOut(function() {;}, 1000);.

What might slow down your site/app is the code that has to run when the timeout triggers.

Upvotes: 1

lem2802
lem2802

Reputation: 1162

the answer is no... you don't have performace problems... but i think you needs to use SetInterval instead SetTimeout to repeat the call every x time

Upvotes: 1

Related Questions