summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2011-11-18 05:13:38 +0100
committersnowleo <schneeleo@gmail.com>2011-11-18 05:13:38 +0100
commit3841648ebad19e6a6ad6a420ac0c0799d392da5c (patch)
tree897c43558a8dae4c20cf3deaebf392126fbae921
parentffc1640308e18f44681c1aaf2c20d7fa5f953b26 (diff)
downloadEssentials-3841648ebad19e6a6ad6a420ac0c0799d392da5c.tar
Essentials-3841648ebad19e6a6ad6a420ac0c0799d392da5c.tar.gz
Essentials-3841648ebad19e6a6ad6a420ac0c0799d392da5c.tar.lz
Essentials-3841648ebad19e6a6ad6a420ac0c0799d392da5c.tar.xz
Essentials-3841648ebad19e6a6ad6a420ac0c0799d392da5c.zip
Update ExecuteTimer to use ns instead of ms for calculations, output is still in ms
-rw-r--r--Essentials/src/com/earth2me/essentials/ExecuteTimer.java19
1 files changed, 12 insertions, 7 deletions
diff --git a/Essentials/src/com/earth2me/essentials/ExecuteTimer.java b/Essentials/src/com/earth2me/essentials/ExecuteTimer.java
index 7a88018c2..301669428 100644
--- a/Essentials/src/com/earth2me/essentials/ExecuteTimer.java
+++ b/Essentials/src/com/earth2me/essentials/ExecuteTimer.java
@@ -1,12 +1,17 @@
package com.earth2me.essentials;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
public class ExecuteTimer
{
- private final List<ExecuteRecord> times;
+ private final transient List<ExecuteRecord> times;
+ private final transient DecimalFormat decimalFormat = new DecimalFormat("#0.000", DecimalFormatSymbols.getInstance(Locale.US));
+
public ExecuteTimer()
{
@@ -24,7 +29,7 @@ public class ExecuteTimer
{
if (!times.isEmpty() || "start".equals(label))
{
- times.add(new ExecuteRecord(label, System.currentTimeMillis()));
+ times.add(new ExecuteRecord(label, System.nanoTime()));
}
}
@@ -36,7 +41,7 @@ public class ExecuteTimer
long time0 = 0;
long time1 = 0;
long time2 = 0;
- long duration;
+ double duration;
for (ExecuteRecord pair : times)
{
@@ -44,8 +49,8 @@ public class ExecuteTimer
time2 = (Long)pair.getTime();
if (time1 > 0)
{
- duration = time2 - time1;
- output.append(mark).append(": ").append(duration).append("ms - ");
+ duration = (time2 - time1)/1000000.0;
+ output.append(mark).append(": ").append(decimalFormat.format(duration)).append("ms - ");
}
else
{
@@ -53,8 +58,8 @@ public class ExecuteTimer
}
time1 = time2;
}
- duration = time1 - time0;
- output.append("Total: ").append(duration).append("ms");
+ duration = (time1 - time0)/1000000.0;
+ output.append("Total: ").append(decimalFormat.format(duration)).append("ms");
times.clear();
return output.toString();
}