Testing the elapsed time between 2 consecultive calls to System.nanoTime()

- 1 test was added

Signed-off-by: Daan Hoogland <daan@onecht.net>
This commit is contained in:
wilderrodrigues 2015-06-23 19:21:29 +02:00 committed by Daan Hoogland
parent 5557ad5588
commit 2f145378df
1 changed files with 14 additions and 0 deletions

View File

@ -94,4 +94,18 @@ public class TestProfiler extends Log4jEnabledTestCase {
Assert.assertTrue(pf.getDurationInMillis() == -1);
Assert.assertFalse(pf.isStopped());
}
@Test
public void testResolution() {
long nanoTime1 = 0l;
long nanoTime2 = 0l;
nanoTime1 = System.nanoTime();
nanoTime2 = System.nanoTime();
System.out.println("Nano time 1: " + nanoTime1);
System.out.println("Nano time 2: " + nanoTime2);
// We are measuring the elapsed time in 2 consecutive calls of System.nanoTime()
// That's the same as 0.002 milliseconds or 2000 nanoseconds.
Assert.assertTrue("It took more than 2 microseconds between 2 consecutive calls to System.nanoTime().", nanoTime2 - nanoTime1 <= 2000);
}
}