Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EQNA6DJ9VgCtW6zhCE8Xud
39 lines
1.5 KiB
Java
Executable File
39 lines
1.5 KiB
Java
Executable File
package com.ankurm.hibernatedemo.testdb;
|
|
|
|
import org.hibernate.SessionFactory;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
* Backs docs/09-testing-in-memory-databases.md, chapter "Startup time, with the caveat this is a shared
|
|
* container". NOT a benchmark -- three runs per database, plain {@code System.nanoTime()},
|
|
* one shared, likely-noisy sandbox container. The numbers are indicative of relative order of
|
|
* magnitude only, and the docs/output file this writes says so explicitly.
|
|
*/
|
|
class StartupTimingTest {
|
|
|
|
private static final Logger DEMO = LoggerFactory.getLogger("DEMO");
|
|
|
|
private long timeOneBuild(TestDbSupport.Db db, String suffix) {
|
|
long start = System.nanoTime();
|
|
SessionFactory sf = TestDbSupport.buildSessionFactory(db, suffix, "create-drop", TestDbWidget.class);
|
|
long elapsedMs = (System.nanoTime() - start) / 1_000_000;
|
|
sf.close();
|
|
return elapsedMs;
|
|
}
|
|
|
|
@Test
|
|
void measureStartupAcrossThreeRunsPerDatabase() {
|
|
TestDbSupport.Db[] dbs = {TestDbSupport.Db.H2, TestDbSupport.Db.HSQLDB, TestDbSupport.Db.DERBY};
|
|
for (TestDbSupport.Db db : dbs) {
|
|
long[] times = new long[3];
|
|
for (int i = 0; i < 3; i++) {
|
|
times[i] = timeOneBuild(db, "timing" + i);
|
|
}
|
|
DEMO.info("startup ms for {} over 3 runs: {}, {}, {} (sandbox container -- indicative only, not a benchmark)",
|
|
db, times[0], times[1], times[2]);
|
|
}
|
|
}
|
|
}
|