mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Replace System.currentTimeMillis() by System.nanoTime()
- System.nanoTime() is the best way to measure elapsed time in Java. - It gives a resolution on the order of microseconds The System.currentTimeMillis() is used when calculating absolut time. Signed-off-by: wilderrodrigues <wrodrigues@schubergphilis.com>
This commit is contained in:
parent
c0a1009740
commit
78c802a539
@ -23,24 +23,20 @@ public class Profiler {
|
||||
private Long startTickInMs;
|
||||
private Long stopTickInMs;
|
||||
|
||||
public Profiler() {
|
||||
startTickInMs = null;
|
||||
stopTickInMs = null;
|
||||
}
|
||||
|
||||
public long start() {
|
||||
startTickInMs = System.currentTimeMillis();
|
||||
startTickInMs = System.nanoTime();
|
||||
return startTickInMs.longValue();
|
||||
}
|
||||
|
||||
public long stop() {
|
||||
stopTickInMs = System.currentTimeMillis();
|
||||
stopTickInMs = System.nanoTime();
|
||||
return stopTickInMs.longValue();
|
||||
}
|
||||
|
||||
public long getDuration() {
|
||||
if (startTickInMs != null && stopTickInMs != null)
|
||||
if (startTickInMs != null && stopTickInMs != null) {
|
||||
return stopTickInMs.longValue() - startTickInMs.longValue();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -55,12 +51,14 @@ public class Profiler {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (startTickInMs == null)
|
||||
if (startTickInMs == null) {
|
||||
return "Not Started";
|
||||
}
|
||||
|
||||
if (stopTickInMs == null)
|
||||
if (stopTickInMs == null) {
|
||||
return "Started but not stopped";
|
||||
}
|
||||
|
||||
return "Done. Duration: " + getDuration() + "ms";
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user