Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add performance comparison to snakeyaml-engine #217

Merged
merged 2 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions snake-kmp-benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ kotlin {
}
}

jvmMain {
dependencies {
implementation("org.snakeyaml:snakeyaml-engine:2.7")
}
}

jsMain {
dependencies {
implementation("net.thauvin.erik.urlencoder:urlencoder-lib:1.5.0") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package it.krzeminski.snakeyaml.engine.kmp.benchmark

import kotlinx.benchmark.*
import okio.Path.Companion.toPath
import okio.buffer
import okio.use
import org.snakeyaml.engine.v2.api.LoadSettings
import org.snakeyaml.engine.v2.api.YamlUnicodeReader
import org.snakeyaml.engine.v2.composer.Composer
import org.snakeyaml.engine.v2.constructor.BaseConstructor
import org.snakeyaml.engine.v2.constructor.StandardConstructor
import org.snakeyaml.engine.v2.parser.ParserImpl
import org.snakeyaml.engine.v2.scanner.StreamReader

@State(Scope.Benchmark)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(BenchmarkTimeUnit.MILLISECONDS)
class SnakeyamlEngineJvmLoadingTimeBenchmark {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be displayed as a separate series on the JVM graph in https://krzema12.github.io/snakeyaml-engine-kmp-benchmarks/dev/bench/

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it will be. Each benchmark is displayed as a separate chart by default (you can modify the index.html in gh-pages branch if you need otherwise)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can modify the index.html in gh-pages branch if you need otherwise

I tried tinkering with JavaScript to have both JVM series on a single graph, but I lost the battle 😅 Maybe another time! This is the feature request on the GitHub action's side: benchmark-action/github-action-benchmark#175

@Param("")
var openAiYamlPath: String = ""

private val loadSettings = LoadSettings.builder().build()

private lateinit var constructor: BaseConstructor

@Setup
fun setUp() {
constructor = StandardConstructor(loadSettings)
}

@Benchmark
fun loadsOpenAiSchema(): Map<*, *> {
return with(fileSystem()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: why don't use just a standard java input stream instead of okio source which later converted to a stream? It is more fair in my opinion

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to keep the setup code as close to the KMP test as possible, to keep the overhead roughly the same to be able to compare both. But thanks for this comment, I'll give it more thought!

openReadOnly(openAiYamlPath.toPath(normalize = true)).use { handle ->
handle.source().buffer().use { source ->
val reader = StreamReader(
loadSettings,
YamlUnicodeReader(source.inputStream()),
)
val composer = Composer(
loadSettings,
ParserImpl(
loadSettings,
reader,
)
)
constructor.constructSingleDocument(composer.getSingleNode()) as Map<*, *>
}
}
}
}
}
Loading