mirror of
https://bitbucket.org/Mattrixwv/javaclasses.git
synced 2025-12-06 23:13:57 -05:00
Updated function for performance
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user