Skip to content

Commit d21c9fe

Browse files
Test Db Application
1 parent 60daaf3 commit d21c9fe

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

jdbc/spring-test-db/src/main/kotlin/tech/ydb/testdb/TestDbApplication.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ class TestDbApplication : CommandLineRunner {
2323
override fun run(vararg args: String?) {
2424
val testString = String(ByteArray(1024) { 'a'.code.toByte() })
2525

26-
val start = Instant.now()
27-
val end = start.plusSeconds(10)
28-
var step = start
26+
var sink = 0
27+
val t0 = System.nanoTime()
28+
val end = t0 + 10_000_000_000L
2929
var count = 0
30-
while (step < end) {
31-
getFixedString(testString)
30+
while (System.nanoTime() < end) {
31+
sink += getFixedString(testString).length
3232
count++
33-
step = Instant.now()
3433
}
35-
val duration = step.toEpochMilli() - start.toEpochMilli()
36-
37-
log.info("Average time = {}ms", 1.0 * duration / count )
34+
val elapsed = System.nanoTime() - t0
35+
val avgMs = elapsed.toDouble() / count / 1_000_000.0
36+
val opsPerSec = count * 1e9 / elapsed
37+
log.info("avg={} ms/op, throughput={} ops/s", avgMs, opsPerSec)
3838
}
3939

4040
fun getFixedString(s: String): String {

0 commit comments

Comments
 (0)