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

Simplify creations of separate benchmark source sets in multiplatform projects #291

Open
fzhinkin opened this issue Feb 11, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@fzhinkin
Copy link
Contributor

Documentation describes a way to place benchmarks in separate source sets. It kinda works when you need a single source set associated with a particular target. However, creating a separate common benchmark source set where benchmarks could be executed for each and every target is quite difficult.

It would be nice to provide an extension function for Project, that'll do that itself, instead of delegating this tedious work to users.

@fzhinkin fzhinkin added the enhancement New feature or request label Feb 11, 2025
@fzhinkin
Copy link
Contributor Author

This is how "manual" configuration looks like now:

kotlin {
    sourceSets {
        val benchmarkMain by creating {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.13")
            }
        }
    }

    val bmm = sourceSets.getByName("benchmarkMain")

    targets.matching { it.name != "metadata" }.all {
        compilations.create("benchmark") {
            associateWith(this@all.compilations.getByName("main"))
            defaultSourceSet {
                dependencies {
                    implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.13")
                }
                dependsOn(bmm)
            }
        }
    }

    targets.matching { it.name != "metadata" }.all {
        benchmark.targets.register("${name}Benchmark")
    }
}

Yes, it could be cleaned up and simplified. Yet, it's hard to come up with something like that unless you spend enough time writing and debugging build scripts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant