Skip to content

Commit

Permalink
KTOR-7941 Benchmark for reading lines in memory with ByteReadChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
bjhham committed Dec 16, 2024
1 parent dfc8712 commit 8e0c591
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions io-benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies {
jmh(libs.ktor.io)
jmh(libs.ktor.utils)
jmh(libs.ktor.network)
jmh(libs.kotlinx.io)
jmh(kotlin("test"))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.ktor.benchmarks

import io.ktor.utils.io.*
import kotlinx.coroutines.*
import org.openjdk.jmh.annotations.*
import kotlin.test.*

@State(Scope.Benchmark)
class IoOperationsBenchmarks {

@Benchmark
fun readLines() = runBlocking {
var lineNumber = 0
var count = 0
val numberOfLines = 100_000
val channel = writer(Dispatchers.IO) {
for (line in generateSequence { "line ${lineNumber++}\n" }.take(numberOfLines))
channel.writeStringUtf8(line)
}.channel
val out = StringBuilder()
while (channel.readUTF8LineTo(out) && count < numberOfLines)
count++

assertEquals(numberOfLines, count)
}

}
4 changes: 3 additions & 1 deletion libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[versions]

kotlin = "2.0.21"
ktor = "3.0.0-rc-1"
ktor = "3.0.2"
kotlinx-serialization = "1.7.3"
kotlinx-atomicfu = "0.25.0"
kotlinx-io = "0.6.0"
okhttp = "4.12.0"
apache-httpclient = "4.5.14"
logback = "1.5.10"
Expand Down Expand Up @@ -34,6 +35,7 @@ apache-httpclient = { module = "org.apache.httpcomponents:httpclient", version.r

logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
kotlinx-io = { module = "org.jetbrains.kotlinx:kotlinx-io-core", version.ref = "kotlinx-io" }

instrumenter = { module = "com.google.code.java-allocation-instrumenter:java-allocation-instrumenter", version.ref = "instrumenter" }

Expand Down

0 comments on commit 8e0c591

Please sign in to comment.