mirror of
https://bitbucket.org/Mattrixwv/javaclasses.git
synced 2025-12-07 07:23: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 }
|
private enum TIME_RESOLUTION{ NANOSECOND, MICROSECOND, MILLISECOND, SECOND, MINUTE, HOUR, ERROR }
|
||||||
//Simulates starting a stopwatch by saving the time
|
//Simulates starting a stopwatch by saving the time
|
||||||
public void start(){
|
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
|
//Make sure the stop time is reset to 0
|
||||||
stopTime = null;
|
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
|
//SImulates stoping a stopwatch by saving the time
|
||||||
public void stop(){
|
public void stop(){
|
||||||
@@ -98,7 +98,8 @@ public class Stopwatch{
|
|||||||
public String getStr(){
|
public String getStr(){
|
||||||
//Get the current duration from time
|
//Get the current duration from time
|
||||||
Double duration = getTime().doubleValue();
|
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;
|
TIME_RESOLUTION resolution;
|
||||||
for(resolution = TIME_RESOLUTION.NANOSECOND;(resolution.ordinal() < TIME_RESOLUTION.SECOND.ordinal()) && (duration >= 1000);resolution = TIME_RESOLUTION.values()[resolution.ordinal() + 1]){
|
for(resolution = TIME_RESOLUTION.NANOSECOND;(resolution.ordinal() < TIME_RESOLUTION.SECOND.ordinal()) && (duration >= 1000);resolution = TIME_RESOLUTION.values()[resolution.ordinal() + 1]){
|
||||||
duration /= 1000;
|
duration /= 1000;
|
||||||
|
|||||||
Reference in New Issue
Block a user