diff --git a/antlr-kotlin-benchmarks/build.gradle.kts b/antlr-kotlin-benchmarks/build.gradle.kts index b70b8ca7..4e759047 100644 --- a/antlr-kotlin-benchmarks/build.gradle.kts +++ b/antlr-kotlin-benchmarks/build.gradle.kts @@ -2,6 +2,7 @@ import com.strumenta.antlrkotlin.gradle.AntlrKotlinTask import com.strumenta.antlrkotlin.gradle.ext.targetsNative import kotlinx.benchmark.gradle.JvmBenchmarkTarget import org.gradle.jvm.tasks.Jar +import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask plugins { @@ -37,10 +38,17 @@ strumentaMultiplatform { kotlin { js { + nodejs() + // Necessary for using @JsModule useCommonJs() } + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + nodejs() + } + mingwX64 { binaries.configureEach { // Increase the function's stack size to 2 megabytes @@ -86,9 +94,9 @@ benchmark { jmhVersion = "1.37" } - // Blocked by https://github.com/Kotlin/kotlinx-benchmark/issues/185 - // register("js") - // register("wasmJs") + register("js") + register("wasmJs") + register("mingwX64") } } diff --git a/antlr-kotlin-benchmarks/src/commonMain/kotlin/org/antlr/v4/kotlinruntime/benchmarks/mysql/MySQLBenchmarks.kt b/antlr-kotlin-benchmarks/src/commonMain/kotlin/org/antlr/v4/kotlinruntime/benchmarks/mysql/MySQLBenchmarks.kt index 4992ff61..4cb746a3 100644 --- a/antlr-kotlin-benchmarks/src/commonMain/kotlin/org/antlr/v4/kotlinruntime/benchmarks/mysql/MySQLBenchmarks.kt +++ b/antlr-kotlin-benchmarks/src/commonMain/kotlin/org/antlr/v4/kotlinruntime/benchmarks/mysql/MySQLBenchmarks.kt @@ -18,8 +18,8 @@ import org.antlr.v4.kotlinruntime.benchmarks.readBenchmarkFile @State(Scope.Benchmark) @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(BenchmarkTimeUnit.MILLISECONDS) -@Warmup(iterations = 4, timeUnit = BenchmarkTimeUnit.MILLISECONDS) -@Measurement(iterations = 8, timeUnit = BenchmarkTimeUnit.MILLISECONDS) +@Warmup(iterations = 4, time = 5, timeUnit = BenchmarkTimeUnit.SECONDS) +@Measurement(iterations = 4, time = 5, timeUnit = BenchmarkTimeUnit.SECONDS) public class MySQLBenchmarks { @Suppress("SpellCheckingInspection") private val charSets = setOf( diff --git a/antlr-kotlin-benchmarks/src/commonTest/kotlin/org/antlr/v4/kotlinruntime/benchmarks/ManualMySQLBenchmarks.kt b/antlr-kotlin-benchmarks/src/commonTest/kotlin/org/antlr/v4/kotlinruntime/benchmarks/ManualMySQLBenchmarks.kt deleted file mode 100644 index a47b8be1..00000000 --- a/antlr-kotlin-benchmarks/src/commonTest/kotlin/org/antlr/v4/kotlinruntime/benchmarks/ManualMySQLBenchmarks.kt +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2017-present Strumenta and contributors, licensed under Apache 2.0. -// Copyright 2024-present Strumenta and contributors, licensed under BSD 3-Clause. -package org.antlr.v4.kotlinruntime.benchmarks - -import org.antlr.v4.kotlinruntime.benchmarks.mysql.MySQLBenchmarks -import kotlin.test.Ignore -import kotlin.test.Test -import kotlin.time.Duration -import kotlin.time.measureTime - -// An handy way to manually run benchmarks, as we can just use the gutter runners. -// Remove the @Ignore annotation to execute them. -// -// TODO(Edoardo): remove once kotlinx-benchmark properly supports the JS target. -// See https://github.com/Kotlin/kotlinx-benchmark/issues/185 -@Ignore -class ManualMySQLBenchmarks { - @Test - fun benchmarks() { - val benchmarks = MySQLBenchmarks() - benchmarks.setup() - - // Warm up - repeat(8) { - val duration = measureTime { - benchmarks.statements() - } - - val ms = milliseconds(duration) - println("Warm up ${it + 1}: $ms ms") - } - - val statementsAvg = averageTimeMs("statements", 8) { - measureTime { - benchmarks.statements() - } - } - - val queriesAvg = averageTimeMs("queries", 8) { - measureTime { - benchmarks.queries() - } - } - - val insertsAvg = averageTimeMs("inserts", 8) { - measureTime { - benchmarks.inserts() - } - } - - print("\nStatements:\t\t$statementsAvg ms") - print("\nQueries:\t\t$queriesAvg ms") - print("\nInserts:\t\t$insertsAvg ms") - } - - private fun averageTimeMs(title: String, times: Int, action: () -> Duration): Double { - require(times > 3) { - "At least 4 iterations are required" - } - - val durations = ArrayList(times) - println("\nBenchmark: $title") - - for (i in 0..): Double { - require(durations.size > 3) { - "At least 4 durations are required" - } - - // Sort and drop the slowest run - val durationsMinusSlowest = durations.asSequence() - .sortedDescending() - .drop(1) - .toList() - - val sum = durationsMinusSlowest.fold(Duration.ZERO) { acc, duration -> acc + duration } - val duration = sum / durationsMinusSlowest.size - return milliseconds(duration) - } - - private fun milliseconds(duration: Duration): Double = - duration.inWholeNanoseconds.toDouble() / 1000000.0 -} diff --git a/antlr-kotlin-benchmarks/src/nativeMain/kotlin/org/antlr/v4/kotlinruntime/benchmarks/IO.kt b/antlr-kotlin-benchmarks/src/nativeMain/kotlin/org/antlr/v4/kotlinruntime/benchmarks/IO.kt index a50ec333..4d88fb18 100644 --- a/antlr-kotlin-benchmarks/src/nativeMain/kotlin/org/antlr/v4/kotlinruntime/benchmarks/IO.kt +++ b/antlr-kotlin-benchmarks/src/nativeMain/kotlin/org/antlr/v4/kotlinruntime/benchmarks/IO.kt @@ -30,7 +30,7 @@ private val dir: String = // TODO(Edoardo): this should probably be replaced by a Gradle task, // but in the meantime it should work consistently -private val basePath = "build/processedResources/$dir/main" +private val basePath = "antlr-kotlin-benchmarks/build/processedResources/$dir/main" public actual fun readBenchmarkFile(name: String): String { val path = Path("$basePath$name") diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 61ce8579..35d93576 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] kotlin = "2.1.20" kotlinx-io = "0.7.0" -kotlinx-benchmark = "0.4.13" +kotlinx-benchmark = "0.4.14" kotlinx-resources = "0.10.0" antlr4 = "4.13.1" dokka = "1.9.20" diff --git a/kotlin-js-store/yarn.lock b/kotlin-js-store/yarn.lock index 3c93df15..81dec9ad 100644 --- a/kotlin-js-store/yarn.lock +++ b/kotlin-js-store/yarn.lock @@ -337,6 +337,14 @@ base64id@2.0.0, base64id@~2.0.0: resolved "https://registry.yarnpkg.com/base64id/-/base64id-2.0.0.tgz#2770ac6bc47d312af97a8bf9a634342e0cd25cb6" integrity sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog== +benchmark@*: + version "2.1.4" + resolved "https://registry.yarnpkg.com/benchmark/-/benchmark-2.1.4.tgz#09f3de31c916425d498cc2ee565a0ebf3c2a5629" + integrity sha512-l9MlfN4M1K/H2fbhfMy3B7vJd6AGKJVQn2h6Sg/Yx+KckoUA7ewS5Vv6TjSq18ooE1kS9hhAlQRH3AkXIh/aOQ== + dependencies: + lodash "^4.17.4" + platform "^1.3.3" + binary-extensions@^2.0.0: version "2.2.0" resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" @@ -1208,7 +1216,7 @@ locate-path@^6.0.0: dependencies: p-locate "^5.0.0" -lodash@^4.17.15, lodash@^4.17.21: +lodash@^4.17.15, lodash@^4.17.21, lodash@^4.17.4: version "4.17.21" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== @@ -1459,6 +1467,11 @@ pkg-dir@^4.2.0: dependencies: find-up "^4.0.0" +platform@^1.3.3: + version "1.3.6" + resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.6.tgz#48b4ce983164b209c2d45a107adb31f473a6e7a7" + integrity sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg== + punycode@^2.1.0: version "2.3.1" resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.3.1.tgz#027422e2faec0b25e1549c3e1bd8309b9133b6e5" @@ -1680,7 +1693,7 @@ source-map-loader@5.0.0: iconv-lite "^0.6.3" source-map-js "^1.0.2" -source-map-support@0.5.21, source-map-support@~0.5.20: +source-map-support@*, source-map-support@0.5.21, source-map-support@~0.5.20: version "0.5.21" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f" integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==