forked from destiny1020/algorithm_playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStopwatch.java
More file actions
44 lines (36 loc) · 733 Bytes
/
Stopwatch.java
File metadata and controls
44 lines (36 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package chap1;
public class Stopwatch
{
private long start;
private long start_nano;
private long duration;
private long duration_nano;
public Stopwatch()
{
this.start = System.currentTimeMillis();
this.start_nano = System.nanoTime();
}
public void stop()
{
this.duration = System.currentTimeMillis() - this.start;
this.duration_nano = System.nanoTime() - this.start_nano;
}
public double elapsedTimeInSeconds()
{
long now = System.currentTimeMillis();
return (now - start) / 1000.0;
}
public long elapsedTime()
{
long now = System.currentTimeMillis();
return (now - start);
}
public long getDuration()
{
return duration;
}
public long getDuration_nano()
{
return duration_nano;
}
}