Timing functions in Javascript

Lately I’ve been working on my app and it’s almost complete. However, before I move forward, I did a lot of testing and I have found that there is a time-lag in my timer function.

So now i am reading about making accurate timing in Javascript. What I didn’t know (according to the page I’m reading) is that Javascript is single-threaded, so it takes time to go through each process. This can cause timing functions to be inaccurate in Javascript.

Here are some articles i’m reading:


I ran into this problem while testing my Pomodoro Clock challenge (which I am turning into a bigger app). So I am now going to have to rewrite my timing function code, because there is quite a large latency that I have noticed.

Maybe I’m getting too deep into it, since it is just a small project, but time is very important, and I think that if I want to do more mathematically intensive projects in the future, getting timing down is important to learn.

Of course, this also makes me want to learn something like Java or C#…

A good (though still hack-y) solution is described here

Keep in mind browsers were built for displaying content, not performing arithmetic or time-sensitive computations. If you decide to dig much deeper you’ll probably need to fall back on server-side processing.