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
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
@NotNull
|
||||
private final LoggerInstance logger;
|
||||
private LoggerInstance logger;
|
||||
|
||||
/**
|
||||
* Constructor, initializes the StarOpenSource Engine.
|
||||
|
@ -79,24 +80,20 @@ public final class Engine {
|
|||
return;
|
||||
}
|
||||
|
||||
// Startup time measurement
|
||||
long initTime = System.currentTimeMillis();
|
||||
long initTime = Miscellaneous.measureExecutionTime(() -> {
|
||||
// Initialize EngineConfiguration and load it
|
||||
new EngineConfiguration();
|
||||
EngineConfiguration.getInstance().loadConfiguration();
|
||||
|
||||
// Initialize EngineConfiguration and load it
|
||||
new EngineConfiguration();
|
||||
EngineConfiguration.getInstance().loadConfiguration();
|
||||
// Initialize classes
|
||||
initializeClasses();
|
||||
|
||||
// Initialize classes
|
||||
initializeClasses();
|
||||
// Populate crash content
|
||||
populateCrashContent();
|
||||
|
||||
// Populate crash content
|
||||
populateCrashContent();
|
||||
|
||||
// Initialize variables
|
||||
logger = new LoggerInstance(new LogIssuer(getClass(), CodePart.ENGINE));
|
||||
|
||||
// Startup time measurement
|
||||
initTime = System.currentTimeMillis() - initTime;
|
||||
// Initialize variables
|
||||
logger = new LoggerInstance(new LogIssuer(getClass(), CodePart.ENGINE));
|
||||
});
|
||||
|
||||
// Print finish message
|
||||
logger.info("Initialized sos!engine v%engine_version% in " + initTime + "ms");
|
||||
|
|
|
@ -62,4 +62,17 @@ public final class Miscellaneous {
|
|||
object = null;
|
||||
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