Skip to content

Commit 3d42e2a

Browse files
committed
feat: Speed up benchmark
1 parent 6a72691 commit 3d42e2a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ dependencies {
4040
}
4141

4242
test {
43-
useJUnitPlatform {
44-
excludeTags 'benchmark'
45-
}
4643
testLogging {
4744
exceptionFormat = 'full'
4845
}

src/test/kotlin/benchmark/MappingBenchmark.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,17 @@ class MappingBenchmark {
4444
}.toList()
4545

4646
val timeMillis = System.currentTimeMillis()
47-
users.map { user ->
47+
users.chunked(4096).map { userChunk ->
48+
val query = StringBuilder()
49+
query.append("INSERT INTO \"user\" (id, name, short_name) VALUES ")
50+
query.append(userChunk.mapIndexed { index, user ->
51+
"(:user$index.id, :user$index.name, :user$index.shortName)"
52+
}.joinToString(","))
53+
query.append(";")
54+
4855
connection.sendPreparedStatement(
49-
"INSERT INTO \"user\" (id, name, short_name) VALUES (:user.id, :user.name, :user.shortName);",
50-
mapOf("user" to user)
56+
query.toString(),
57+
userChunk.mapIndexed { index, user -> "user$index" to user }.toMap()
5158
)
5259
}.forEach { it.get() }
5360
println("Insert of $amount users took: ${System.currentTimeMillis() - timeMillis}")

0 commit comments

Comments
 (0)