Reputation: 8182
Being that javascript is single threaded, is there a different between having multiple intervals and having one interval calling multiple functions?
Upvotes: 2
Views: 1556
Reputation: 3297
Check out Google's analysis of timer use for Gmail Mobile. The short version is that creating lots of timers with a delay of one second or more doesn't noticeably impact performance. But lots of timers with 100-200ms delays made the UI feel sluggish. As a result, they chose to use a hybrid approach of a single global high-frequency timer for the short timers and separate timers for longer timers.
Upvotes: 5
Reputation: 413720
Assuming that there's more overhead in event dispatch than there is in a simple function call, if you want to do 20 things every 100 milliseconds you're probably better off with a single handler that calls 20 functions than with 20 different timers.
With your own function, you can also ensure a consistent invocation sequence. (Browsers are pretty consistent with timer dispatch, but it's a little flaky to rely on that.)
If you're worried about this strictly for performance reasons, then I'd say don't worry about it unless you've got a whole lot of timers going on.
Upvotes: 2