I am counting some things that I cannot just put into a long cycle. And I need time to see how long they finish, but it looks like the timer has an accuracy of 15-16 ms in java? How can I get around this?
Have you tried to use System.nanoTime () ?
From Javadoc:
Returns the current value of the most accurate available system timer in nanoseconds.This method can only be used to measure elapsed time and is not related to any other concept of system or wall time. The return value is nanoseconds from some fixed but arbitrary time (possibly in the future, so the values ββmay be negative). This method provides nanosecond accuracy, but not necessarily nanosecond accuracy. No guarantees are made as to how often values ββchange. Differences in consecutive calls that span more than 292 years (2 63 nanoseconds) will not accurately calculate elapsed time due to numerical overflow.For example, to determine how long it takes to execute code:long startTime = System.nanoTime (); // ... measured code ... long ratedTime = System.nanoTime () - startTime;
Returns the current value of the most accurate available system timer in nanoseconds.
This method can only be used to measure elapsed time and is not related to any other concept of system or wall time. The return value is nanoseconds from some fixed but arbitrary time (possibly in the future, so the values ββmay be negative). This method provides nanosecond accuracy, but not necessarily nanosecond accuracy. No guarantees are made as to how often values ββchange. Differences in consecutive calls that span more than 292 years (2 63 nanoseconds) will not accurately calculate elapsed time due to numerical overflow.
For example, to determine how long it takes to execute code:
long startTime = System.nanoTime (); // ... measured code ... long ratedTime = System.nanoTime () - startTime;
Clocks and timers - general overview
The Java programming API for clocks and timers Absolute Clock "time of day" presents the method System.currentTimeMillis () which returns a millisecond representation of the time of a wall clock in milliseconds from the era. As such, it uses the operating system βtime of the day.β The update resolution of this watch often coincides with a timer (for example, 10 ms), but some systems are fixed, regardless of the interrupt rate.A clock with relative time using the System.nanoTime () method, which returns "free time" in nanoseconds. This time is only useful for comparison with other nanoTime values. The nanoTime method uses the high-resolution clock available to the platform, and while its return value is in nanoseconds, the resolution update is usually microseconds. However, on some systems there is no choice but to use the same clock source currentTimeMillis () - fortunately this is rare and mainly affects older Linux systems and Windows 98.
The Java programming API for clocks and timers Absolute Clock "time of day" presents the method System.currentTimeMillis () which returns a millisecond representation of the time of a wall clock in milliseconds from the era. As such, it uses the operating system βtime of the day.β The update resolution of this watch often coincides with a timer (for example, 10 ms), but some systems are fixed, regardless of the interrupt rate.
A clock with relative time using the System.nanoTime () method, which returns "free time" in nanoseconds. This time is only useful for comparison with other nanoTime values. The nanoTime method uses the high-resolution clock available to the platform, and while its return value is in nanoseconds, the resolution update is usually microseconds. However, on some systems there is no choice but to use the same clock source currentTimeMillis () - fortunately this is rare and mainly affects older Linux systems and Windows 98.