Total Complexity | 2 |
Total Lines | 18 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | package io.github.glytching.junit.extension.benchmark; |
||
9 | public class StopWatch { |
||
10 | |||
11 | private long start; |
||
12 | |||
13 | /** Constructs a StopWatch with a start time equal to the system's current nano time. */ |
||
14 | public StopWatch() { |
||
15 | this.start = nanoTime(); |
||
16 | } |
||
17 | |||
18 | /** |
||
19 | * Returns the duration of since this instance was created. The duration will be converted into |
||
20 | * the given {@code timeUnit}. |
||
21 | * |
||
22 | * @param timeUnit the units in which the duration is returned |
||
23 | * @return The elapsed time converted to the specified units |
||
24 | */ |
||
25 | public long duration(TimeUnit timeUnit) { |
||
26 | return timeUnit.convert(nanoTime() - start, NANOSECONDS); |
||
27 | } |
||
29 |