From 1e4cb3316ebb60c7eb7f23f94a3b3e2a0f5b0cfc Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Fri, 12 Jun 2020 15:03:04 -0400 Subject: [PATCH] Updated function for performance --- src/main/java/mattrixwv/Stopwatch.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/mattrixwv/Stopwatch.java b/src/main/java/mattrixwv/Stopwatch.java index 6c4cfa9..c57215c 100644 --- a/src/main/java/mattrixwv/Stopwatch.java +++ b/src/main/java/mattrixwv/Stopwatch.java @@ -50,10 +50,10 @@ public class Stopwatch{ private enum TIME_RESOLUTION{ NANOSECOND, MICROSECOND, MILLISECOND, SECOND, MINUTE, HOUR, ERROR } //Simulates starting a stopwatch by saving the time public void start(){ - //Get the time as close to calling the function as possible - startTime = System.nanoTime(); //Make sure the stop time is reset to 0 stopTime = null; + //Get the time as close to returning from the function as possible + startTime = System.nanoTime(); } //SImulates stoping a stopwatch by saving the time public void stop(){ @@ -98,7 +98,8 @@ public class Stopwatch{ public String getStr(){ //Get the current duration from time Double duration = getTime().doubleValue(); - //Reduce the number to the appropriate number of digits. (xxx.x). This loop works down to seconds + //Reduce the number to the appropriate number of digits. (xxx.x). + //This loop works down to seconds TIME_RESOLUTION resolution; for(resolution = TIME_RESOLUTION.NANOSECOND;(resolution.ordinal() < TIME_RESOLUTION.SECOND.ordinal()) && (duration >= 1000);resolution = TIME_RESOLUTION.values()[resolution.ordinal() + 1]){ duration /= 1000;