Skip to content

Commit

Permalink
Action sbt scalafmtAll
Browse files Browse the repository at this point in the history
  • Loading branch information
takapi327 committed Aug 14, 2024
1 parent 878c2f1 commit 8c8bc61
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 68 deletions.
20 changes: 10 additions & 10 deletions benchmark/src/main/scala/benchmark/connector/jdbc/Select.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ class Select:

@Benchmark
def prepareStatement: List[BenchmarkType] =
connection
.use { conn =>
for
statement <- conn.prepareStatement("SELECT * FROM jdbc_prepare_statement_test LIMIT ?")
_ <- statement.setInt(1, len)
resultSet <- statement.executeQuery()
records <- consume(resultSet)
yield records
}
.unsafeRunSync()
connection
.use { conn =>
for
statement <- conn.prepareStatement("SELECT * FROM jdbc_prepare_statement_test LIMIT ?")
_ <- statement.setInt(1, len)
resultSet <- statement.executeQuery()
records <- consume(resultSet)
yield records
}
.unsafeRunSync()

private def consume(resultSet: ResultSet[IO]): IO[List[BenchmarkType]] =
def loop(acc: Vector[BenchmarkType]): IO[Vector[BenchmarkType]] =
Expand Down
22 changes: 11 additions & 11 deletions benchmark/src/main/scala/benchmark/connector/ldbc/Select.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ class Select:
for
statement <- conn.createStatement()
resultSet <- statement.executeQuery(s"SELECT * FROM jdbc_statement_test LIMIT $len")
records <- consume(resultSet)
records <- consume(resultSet)
yield records
}
.unsafeRunSync()

@Benchmark
def prepareStatement: List[BenchmarkType] =
connection
.use { conn =>
for
statement <- conn.prepareStatement("SELECT * FROM jdbc_prepare_statement_test LIMIT ?")
_ <- statement.setInt(1, len)
resultSet <- statement.executeQuery()
records <- consume(resultSet)
yield records
}
.unsafeRunSync()
connection
.use { conn =>
for
statement <- conn.prepareStatement("SELECT * FROM jdbc_prepare_statement_test LIMIT ?")
_ <- statement.setInt(1, len)
resultSet <- statement.executeQuery()
records <- consume(resultSet)
yield records
}
.unsafeRunSync()

private def consume(resultSet: ResultSet[IO]): IO[List[BenchmarkType]] =
def loop(acc: Vector[BenchmarkType]): IO[Vector[BenchmarkType]] =
Expand Down
24 changes: 14 additions & 10 deletions benchmark/src/main/scala/benchmark/wrapper/doobie/Insert.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,20 @@ class Insert:

@Benchmark
def insertN: Unit =
transactor.use { xa =>
(sql"INSERT INTO test (c1, c2)" ++ values(records)).update.run
.transact(xa)
}.unsafeRunSync()
transactor
.use { xa =>
(sql"INSERT INTO test (c1, c2)" ++ values(records)).update.run
.transact(xa)
}
.unsafeRunSync()

@Benchmark
def batchN: Unit =
transactor.use { xa =>
val sql = "INSERT INTO test (c1, c2) VALUES (?, ?)"
Update[(Int, String)](sql)
.updateMany(records)
.transact(xa)
}.unsafeRunSync()
transactor
.use { xa =>
val sql = "INSERT INTO test (c1, c2) VALUES (?, ?)"
Update[(Int, String)](sql)
.updateMany(records)
.transact(xa)
}
.unsafeRunSync()
14 changes: 8 additions & 6 deletions benchmark/src/main/scala/benchmark/wrapper/doobie/Select.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ class Select:

@Benchmark
def selectN: List[(Int, String, String)] =
transactor.use { xa =>
sql"SELECT ID, Name, CountryCode FROM city LIMIT $len"
.query[(Int, String, String)]
.to[List]
.transact(xa)
}.unsafeRunSync()
transactor
.use { xa =>
sql"SELECT ID, Name, CountryCode FROM city LIMIT $len"
.query[(Int, String, String)]
.to[List]
.transact(xa)
}
.unsafeRunSync()
29 changes: 16 additions & 13 deletions benchmark/src/main/scala/benchmark/wrapper/ldbc/Insert.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Insert:
val datasource = jdbc.connector.MysqlDataSource[IO](ds)

connection = Resource.make(datasource.getConnection)(_.close())

records = (1 to len).map(num => (num, s"record$num")).toList

query = Table[Test]
Expand All @@ -59,20 +59,23 @@ class Insert:

@Benchmark
def queryInsertN: Unit =
connection.use { conn =>
query
.insertInto(test => (test.c1, test.c2))
.values(records)
.update
.commit(conn)
}.unsafeRunSync()
connection
.use { conn =>
query
.insertInto(test => (test.c1, test.c2))
.values(records)
.update
.commit(conn)
}
.unsafeRunSync()

@Benchmark
def dslInsertN: Unit =
connection.use { conn =>
(sql"INSERT INTO test (c1, c2)" ++ values(NonEmptyList.fromListUnsafe(records)))
.update
.commit(conn)
}.unsafeRunSync()
connection
.use { conn =>
(sql"INSERT INTO test (c1, c2)" ++ values(NonEmptyList.fromListUnsafe(records))).update
.commit(conn)
}
.unsafeRunSync()

case class Test(id: Option[Int], c1: Int, c2: String) derives Table
32 changes: 18 additions & 14 deletions benchmark/src/main/scala/benchmark/wrapper/ldbc/Select.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,24 @@ class Select:

@Benchmark
def querySelectN: List[(Int, String, String)] =
connection.use { conn =>
query
.select(city => (city.id, city.name, city.countryCode))
.limit(len)
.query
.to[List]
.readOnly(conn)
}.unsafeRunSync()
connection
.use { conn =>
query
.select(city => (city.id, city.name, city.countryCode))
.limit(len)
.query
.to[List]
.readOnly(conn)
}
.unsafeRunSync()

@Benchmark
def dslSelectN: List[(Int, String, String)] =
connection.use { conn =>
sql"SELECT ID, Name, CountryCode FROM city LIMIT $len"
.query[(Int, String, String)]
.to[List]
.readOnly(conn)
}.unsafeRunSync()
connection
.use { conn =>
sql"SELECT ID, Name, CountryCode FROM city LIMIT $len"
.query[(Int, String, String)]
.to[List]
.readOnly(conn)
}
.unsafeRunSync()
8 changes: 4 additions & 4 deletions benchmark/src/main/scala/benchmark/wrapper/slick/Insert.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ class Insert:

@Benchmark
def batchN: Unit =
Await.result(
db.run(query ++= records),
Duration.Inf
)
Await.result(
db.run(query ++= records),
Duration.Inf
)

case class Test(id: Option[Int], c1: Int, c2: String)
class TestTable(tag: Tag) extends Table[Test](tag, "test"):
Expand Down

0 comments on commit 8c8bc61

Please sign in to comment.