View Full Version : Tracking time in miliseconds: is it reliable?

11-14-2013, 03:11 AM
For a scientific project, I need to track reaction times: how long does it take for someone to push a button? I need this to be accurate to the milisecond (or very close).

Can Javascript do this? Is the timer within Javascript reliable 1) at the level of miliseconds, and 2) at a constant (real-world seconds) rate?
And is there any known accuracy cutoff? (An article linked to below suggests 15ms.)

And is there any variation by browser and/or method for tracking the time?

To repeat: I'm interested in time elapsed between two events. I don't care at all what time it is.

If this is a potential problem in Javascript, I'll need to find some alternative.

I've done a bit of searching and have come across some information, but it's not entirely clear:

11-18-2013, 05:44 AM
I've had trouble getting any answers for this. For one thing, this isn't a typical use of Javascript, so it may just be that this is not the best language to use (but it's convenient for me). I'm writing this post just to follow up in case anyone else has similar questions. I'd love to hear from someone else who does know about this, if that someone exists :)

I did write up a working version of my intended application, and it works smoothly. The milliseconds, as far as I can tell, are reliable to the individual ms. The reasoning: it doesn't round and there aren't any obvious patterns. But that's not entirely conclusive. It just rules out the biggest potential issues.

It comes down to four dimensions of potential problems, I think:
1. Consistency from trial to trial.
2. Variability from machine to machine.
3. Precision (decimal points).
4. Smoothness during a given trial.

Here's what I've found out:
1. I have no idea. I haven't noticed any problems, but it's basically impossible to know whether key presses (as I'm using to test this) are the same, but just overall, it looks fine. I'm going to assume it's ok.

2. I assume this is a major problem, and an article I linked to above suggests some browsers only track the time every 15ms, which is a problem as well. But for me, I actually don't need this-- I'm just running it locally. I'd suggest extensive testing if you want this to work widely on the internet.

3. For me, using Firefox (Mac) and Chrome (PC), this seems to work fine, down to the millisecond. It doesn't go beyond that, but I get different results of, for example, "137ms" or "134ms", etc., so it looks like it's precise.

4. Smoothness is probably negatively affected by a busy computer. But even so, I have a number of processes running and haven't noticed any problems. When I'm running this for my actual experiment (the end goal here), I'll only have this running, of course.

11-28-2013, 02:36 PM
I think I have one somewhere from a very old class, will search thru my files and see if I can find it.

11-28-2013, 06:47 PM
I'm interested in time elapsed between two events. I don't care at all what time it is.

Are these "one-off" events? Or can you repeat them ad nauseam and take an average?
Your mention of "key presses" would seem to indicate that you only have one shot at each interval.

11-28-2013, 07:40 PM
Hi capecodlilly2,
I already have working code, but I am still wondering about the reliability. So if you have any info on that it would be much appreciated!

Are these "one-off" events? Or can you repeat them ad nauseam and take an average?
Your mention of "key presses" would seem to indicate that you only have one shot at each interval. My question is about one-off events, I suppose. I'm wondering about in the simplest case how accurate JS is.
However, for my project I actually will have multiple events, but not exact repetitions.

I'm building a task for testing procedural memory-- you will push a key on the keyboard corresponding to the location of a marker on the screen. Then that marker moves, and you push a different key. Repeat. There will be somewhere between 20-100 iterations every time. Over time, the user will improve (because of just getting better at the system or patterns in the movement). And I'm interested in comparing users to each other.

So I don't really care about the exact accuracy of any individual event, but I do need the average reaction time [=time between events] to be reliably measured.

11-28-2013, 10:00 PM
Oh, mine is just telling time, just a simple one, and you refresh for the exact time. Its not what you want, but I finally did find it, its really not what I remembered it to be.
But there are so many people here who will most likely come up with something really cool for you.

11-28-2013, 10:19 PM
@Daniel - that's what I figured (one-off events). If it were something repeatable, I was going to recommend looping+averaging …but that wouldn't be useful in this case.

11-29-2013, 02:51 AM
capecodlilly, thanks anyway! I appreciate it.

traq, correct. This is user input. If a single instance isn't particularly accurate that's workable, but on average I'd need it to be reliable so that it can average over their behavior, rather than averaging over JS response times.

As I said above, this does seem accurate. I'm not entirely sure how reliable it is (and have no idea how I could check), but it looks like it's working. I'd also be hesitant to compare across machines. Luckily this will all be local for me at the moment.