forked from StarOpenSource/Engine
Add Miscellaneous#measureExecutionTime method
This commit is contained in:
parent
d39143d01a
commit
95446a2562
2 changed files with 26 additions and 16 deletions
|
@ -60,8 +60,9 @@ public final class Engine {
|
||||||
* @see LoggerInstance
|
* @see LoggerInstance
|
||||||
* @since 1-alpha0
|
* @since 1-alpha0
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||||
@NotNull
|
@NotNull
|
||||||
private final LoggerInstance logger;
|
private LoggerInstance logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor, initializes the StarOpenSource Engine.
|
* Constructor, initializes the StarOpenSource Engine.
|
||||||
|
@ -79,24 +80,20 @@ public final class Engine {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Startup time measurement
|
long initTime = Miscellaneous.measureExecutionTime(() -> {
|
||||||
long initTime = System.currentTimeMillis();
|
// Initialize EngineConfiguration and load it
|
||||||
|
new EngineConfiguration();
|
||||||
|
EngineConfiguration.getInstance().loadConfiguration();
|
||||||
|
|
||||||
// Initialize EngineConfiguration and load it
|
// Initialize classes
|
||||||
new EngineConfiguration();
|
initializeClasses();
|
||||||
EngineConfiguration.getInstance().loadConfiguration();
|
|
||||||
|
|
||||||
// Initialize classes
|
// Populate crash content
|
||||||
initializeClasses();
|
populateCrashContent();
|
||||||
|
|
||||||
// Populate crash content
|
// Initialize variables
|
||||||
populateCrashContent();
|
logger = new LoggerInstance(new LogIssuer(getClass(), CodePart.ENGINE));
|
||||||
|
});
|
||||||
// Initialize variables
|
|
||||||
logger = new LoggerInstance(new LogIssuer(getClass(), CodePart.ENGINE));
|
|
||||||
|
|
||||||
// Startup time measurement
|
|
||||||
initTime = System.currentTimeMillis() - initTime;
|
|
||||||
|
|
||||||
// Print finish message
|
// Print finish message
|
||||||
logger.info("Initialized sos!engine v%engine_version% in " + initTime + "ms");
|
logger.info("Initialized sos!engine v%engine_version% in " + initTime + "ms");
|
||||||
|
|
|
@ -62,4 +62,17 @@ public final class Miscellaneous {
|
||||||
object = null;
|
object = null;
|
||||||
while(weakReference.get() != null) System.gc();
|
while(weakReference.get() != null) System.gc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Measures the execution time of a {@link Runnable}.
|
||||||
|
*
|
||||||
|
* @param runnable the {@link Runnable} to execute
|
||||||
|
* @see Runnable
|
||||||
|
* @since 1-alpha0
|
||||||
|
*/
|
||||||
|
public static long measureExecutionTime(Runnable runnable) {
|
||||||
|
long initTime = System.currentTimeMillis();
|
||||||
|
runnable.run();
|
||||||
|
return System.currentTimeMillis() - initTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue