-
Notifications
You must be signed in to change notification settings - Fork 4
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 { | ||
@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()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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<*, *> | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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/
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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