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,9 +80,7 @@ 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();
|
||||
|
@ -94,9 +93,7 @@ public final class Engine {
|
|||
|
||||
// Initialize variables
|
||||
logger = new LoggerInstance(new LogIssuer(getClass(), CodePart.ENGINE));
|
||||
|
||||
// Startup time measurement
|
||||
initTime = System.currentTimeMillis() - initTime;
|
||||
});
|
||||
|
||||
// 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