question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Separating source sets for benchmarks in multiplatform projects

See original GitHub issue

I’ve tried adding:

val commonBenchmark by creating {
    dependsOn(commonMain) // or commonTest

    dependencies {
        implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.3.1")
        implementation("com.goncalossilva:resources:0.2.1")
    }
}

And then configuring targets as documented:

benchmark {
    targets {
        register("js")
		// register("jvm")
        // ...
    }
}

But this is clearly not the right way, since nothing happens when running (“Test events were not received”) and there is this warning:

The Kotlin source set commonBenchmark was configured but not added to any Kotlin compilation. You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
BUILD SUCCESSFUL in 5s
1 actionable task: 1 executed
> Task :assembleBenchmarks UP-TO-DATE
> Task :kotlinNpmCachesSetup
> Task :jsPackageJson
> Task :kotlinNodeJsSetup UP-TO-DATE
> Task :kotlinYarnSetup UP-TO-DATE
> Task :jsBenchmarkPackageJson UP-TO-DATE
> Task :rootPackageJson
> Task :kotlinNpmInstall
> Task :jsGenerateExternalsIntegrated SKIPPED
> Task :compileKotlinJs UP-TO-DATE
> Task :jsProcessResources NO-SOURCE
> Task :jsMainClasses UP-TO-DATE
> Task :jsBenchmarkGenerate UP-TO-DATE
> Task :compileBenchmarkKotlinJs NO-SOURCE
> Task :jsBenchmark SKIPPED
> Task :benchmark UP-TO-DATE
BUILD SUCCESSFUL in 723ms
9 actionable tasks: 4 executed, 5 up-to-date
23:44:03: Execution finished 'benchmark'

Could this be documented?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ephemientcommented, Dec 13, 2021

Copied more directly from my actual project which uses the name “bench”, not “benchmark”; perhaps the latter conflicts with some things kotlinx-benchmark sets up itself. (You did remove register("js") though, right?)

1reaction
ephemientcommented, Dec 13, 2021

Yeah the docs aren’t explicit about how to do it, but you need to create a compilation for that sourceset.

kotlin {
    targets {
        js {
            compilations.create("bench")
        }
    }
    sourceSets {
        val commonBench by creating {
            dependsOn(commonMain)
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.0")
            }
        }
        val jsBench by existing {
            dependsOn(commonBench)
            dependsOn(jsMain)
        }
    }
}
benchmark {
    targets {
        register("jsBench")
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Jvm bench in multiplatform with separate SourceSet ... - GitHub
I'm trying to benchmark jvm on a multiplatform project with separate sourceSet To reproduce just clone this branch This is my setup so...
Read more >
Kotlin multiplatform benchmarking toolkit - Android Example 365
kotlinx.benchmark is a toolkit for running benchmarks for multiplatform code written in Kotlin and running on the next supported targets: JVM, ...
Read more >
Support hierarchical project structure of multiplatform projects ...
The subject is about multiplatform projects which have intermediate platfrom-agnostic source sets in the hierarchy between the default common ones ( commonMain ...
Read more >
Understand Multiplatform project structure - Kotlin
Source sets form a hierarchy, which is used for sharing the common code. In a source set shared among several targets, you can...
Read more >
Configuring a multiplatform app - Apple Developer
By default, apps that share a multiplatform target share project settings, so you only need to set ... Otherwise, use a separate target...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found