Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does setTimeout() affects performance

Tags:

javascript

I wonder if this code is going to put load on the client since the timeout is so long?

        //and update this again in a bit
        setTimeout(function() {
            updateWeather(lat,lng);
        }, 60000);
like image 643
Matt Welander Avatar asked Oct 24 '13 23:10

Matt Welander


People also ask

Does setTimeout cause memory leak?

setTimeout and setInterval are the two timing events available in JavaScript. The setTimeout function executes when the given time is elapsed, whereas setInterval executes repeatedly for the given time interval. These timers are the most common cause of memory leaks.

Is setTimeout better than setInterval?

setTimeout allows us to run a function once after the interval of time. setInterval allows us to run a function repeatedly, starting after the interval of time, then repeating continuously at that interval.

What will happen if we call setTimeout () with a time of 0 ms?

1 Answer. To explain: If you call setTimeout() with a time of 0 ms, the function you specify is not invoked right away. Instead, it is placed on a queue to be invoked “as soon as possible” after any currently pending event handlers finish running.

Is setTimeout safe?

setTimeout should be fine. It's only really delayed if there's blocking code running at the moment when it's meant to execute. So setTimeout is typically 20 milliseconds late.


1 Answers

Not that code alone. The system idles for that one minute. As long as updateWeather doesn't have severe performance issues and the interval is short, setTimeout won't be a product (and I believe you mean setInterval, not setTimeout for recurring checks)

like image 57
bobbybee Avatar answered Sep 22 '22 13:09

bobbybee