Java time resolution

I am writing a Java program to run psychology experiments. Since this is a generic program that may be configured for running some reaction time (RT) experiments, I am worried about the time resolution of Java. It turns out that I don't need to worry too much, except on Windows. On Linux, one millisecond time resolution can be consistently achieved using either System.currentTimeMillis() or System.nanoTime() call. On Windows, the former call can only get resolution on the order of ten millisecond, and the later one can get one millisecond most of the times, but can be far worse some times. You can download this code to test it out on your own system.

BTW, this test code apparently was edited on Windows, whose text files end each line with an extra character. In *nix, it shows up as ^M. To remove them, use :%s/^v^m//g in vim, where ^v (control-v) is a control character (SYN).


Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <div> <h1><h2><h3><sub><sup><b><i><u><font><img>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.

More information about formatting options

To prevent automated spam submissions leave this field empty.
Nice place