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

Examples don't work for Kotlin Multiplatform project #96

Closed
aSemy opened this issue Jul 31, 2022 · 2 comments
Closed

Examples don't work for Kotlin Multiplatform project #96

aSemy opened this issue Jul 31, 2022 · 2 comments
Labels

Comments

@aSemy
Copy link

aSemy commented Jul 31, 2022

I've tried copying the examples

but I can't make any good progress, I immediately come across fatal errors.

Cannot find a benchmark compilation 'main', ignoring.
* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':modules:client-tests'

Caused by: java.lang.IllegalStateException: Could not create domain object 'main' (BenchmarkTarget)

Caused by: java.lang.ClassCastException: class kotlinx.benchmark.gradle.BenchmarkTarget cannot be cast to class kotlinx.benchmark.gradle.JvmBenchmarkTarget (kotlinx.benchmark.gradle.BenchmarkTarget and kotlinx.benchmark.gradle.JvmBenchmarkTarget are in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @6e21e3fb)
  • Kotlin 1.7.10
  • Kotlinx Benchmark 0.4.4
import kotlinx.benchmark.gradle.JvmBenchmarkTarget

plugins {
    buildsrc.convention.`kotlin-multiplatform` // convention plugin that applies kotlin("multiplatform") 1.7.10

    id("org.jetbrains.kotlinx.benchmark")
    kotlin("plugin.allopen")
}

kotlin {
    jvm()

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(kotlin("reflect"))

                implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.4")
            }
        }

        val commonTest by getting {
            dependencies {
                implementation(projects.modules.mockk)
            }
        }

        val jvmMain by getting {
            dependencies {
            }
        }

        val jvmTest by getting {
            dependencies {
                implementation(buildsrc.config.Deps.Libs.kotlinTestJunit()) {
                    exclude(group = "junit", module = "junit")
                }

                implementation(buildsrc.config.Deps.Libs.slfj)
                implementation(buildsrc.config.Deps.Libs.logback)

                implementation(buildsrc.config.Deps.Libs.junitJupiter)
            }
        }
    }
}

benchmark {
    configurations {
        named("main") {
            iterationTime = 60
            iterationTimeUnit = "sec"
            iterations = 2
            warmups = 1
        }
    }
    targets {
        register("main") {
            this as JvmBenchmarkTarget
            jmhVersion = "1.33"
        }
    }
}

allOpen {
    annotation("org.openjdk.jmh.annotations.State")
}
@deepak-nulu
Copy link

deepak-nulu commented Dec 4, 2022

@aSemy the following commit shows how I got it working in my multi-platform project. It is a minimal commit with just the changes. Make sure you read the README.md file in the commit, especially if you only have common benchmarks and no JVM-specific benchmarks.

tree-ware/tree-ware-kotlin-core@25d2841

The benchmark tasks then show up in the Gradle panel on the right (in IntelliJ IDEA) in their own category of tasks:

Screen Shot 2022-12-04 at 12 30 38 PM

OndrejSliva pushed a commit to OndrejSliva/kotlinx-benchmark that referenced this issue Jan 10, 2024
…sion-1.8.0-RC2

build(deps): bump kotlin.version from 1.8.0-RC to 1.8.0-RC2
@qurbonzoda
Copy link
Collaborator

Hi,

Since your report, we have significantly improved the documentation. The README now contains a step-by-step guide for setting up a Kotlin Multiplatform project for benchmarking. The sample projects still need improvement, and we have a separate issue to track this progress.

Thanks for the feedback. Please don't hesitate to report new issues if you encounter any challenges with using the library.

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

No branches or pull requests

3 participants