Giter Site home page Giter Site logo

Comments (8)

ephemient avatar ephemient commented on August 17, 2024 1

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")
    }
}

from kotlinx-benchmark.

ephemient avatar ephemient commented on August 17, 2024 1

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?)

from kotlinx-benchmark.

deepak-nulu avatar deepak-nulu commented on August 17, 2024 1

The following commit shows how I got it working in my multi-platform project based on the responses from @ephemient.

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

from kotlinx-benchmark.

goncalossilva avatar goncalossilva commented on August 17, 2024

Thanks! I'm unable to make this work:

> Cannot add a KotlinJsIrCompilation with name 'benchmark' as a KotlinJsIrCompilation with that name already exists.


If I remove js { compilations.create("benchmark") }, then I get:

KotlinSourceSet with name 'jsBenchmark' not found.


If instead I remove register("jsBenchmark"), I get:

Caused by: java.lang.IllegalStateException: Projects must be configuring

from kotlinx-benchmark.

elect86 avatar elect86 commented on August 17, 2024

A little hint (I still cant get this working though), targets in kotlin { } has to go after sourceSets { }

from kotlinx-benchmark.

ephemient avatar ephemient commented on August 17, 2024

That shouldn't be necessary. My actual project: https://github.com/ephemient/aoc2021/blob/main/kt/build.gradle.kts (contains a lot of extra stuff you don't care about, but it runs benchmarks on a single target's "bench" compilation/sourceset).

from kotlinx-benchmark.

elect86 avatar elect86 commented on August 17, 2024

If I dont, I do get

KotlinSourceSet with name 'jvmBench' not found. // jsBenchmark in your (second) case

from kotlinx-benchmark.

BartArys avatar BartArys commented on August 17, 2024

For those who followed @ephemient's instructions and are getting the following gradle error:

Project#afterEvaluate(Action) on project ':rest-ktor' cannot be executed in the current context.

You'll want to change the existing to getting from:

        val jsBench by existing {
            dependsOn(commonBench)
            dependsOn(jsMain)
        }

to:

        val jsBench by getting {
            dependsOn(commonBench)
            dependsOn(jsMain)
        }

from kotlinx-benchmark.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.