Add Miscellaneous#measureExecutionTime method

This commit is contained in:
JeremyStar™ 2024-06-10 18:55:01 +02:00
parent d39143d01a
commit 95446a2562
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 26 additions and 16 deletions

View file

@ -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,9 +80,7 @@ public final class Engine {
return; return;
} }
// Startup time measurement long initTime = Miscellaneous.measureExecutionTime(() -> {
long initTime = System.currentTimeMillis();
// Initialize EngineConfiguration and load it // Initialize EngineConfiguration and load it
new EngineConfiguration(); new EngineConfiguration();
EngineConfiguration.getInstance().loadConfiguration(); EngineConfiguration.getInstance().loadConfiguration();
@ -94,9 +93,7 @@ public final class Engine {
// Initialize variables // Initialize variables
logger = new LoggerInstance(new LogIssuer(getClass(), CodePart.ENGINE)); 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");

View file

@ -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;
}
} }