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

Unclear how to use this lib on android projects (for kotlin code) #206

Open
carstenhag opened this issue May 3, 2024 · 4 comments
Open

Comments

@carstenhag
Copy link

I tried to follow the Kotlin/JVM setup https://github.com/Kotlin/kotlinx-benchmark/blob/master/docs/kotlin-jvm-project-setup.md but unfortunately I could not get it working.

I have added the plugin & benchmark runtime dependency and added this to the build.gradle:

benchmark {
    targets {
        register("main") // also tried app.main
    }
}

I can import the annotations, but they are giving errors.

Screenshot 2024-05-03 at 08 54 00

Running ./gradlew benchmark returns > Configure project :app Warning: Cannot find a benchmark sourceSet 'main', ignoring.

@carstenhag
Copy link
Author

I found at https://kotlinlang.org/docs/gsoc-2024.html#support-android-target-in-kotlinx-benchmark-medium-175-hrs that Android as target is not supported, but the benchmark I want to run is JVM/Kotlin-only.

@fzhinkin
Copy link
Contributor

fzhinkin commented May 3, 2024

but the benchmark I want to run is JVM/Kotlin-only.

@carstenhag, do you mean it's a separate module with either Kotlin/JVM (kotlin("jvm")) or Java (id("java")) plugin applied to it?

I'm clarifying because android projects usually mean a project with the Android Gradle plugin applied to it, and unfortunately, kotlinx-benchmark does not currently support such projects at the moment.

@carstenhag
Copy link
Author

I mean a project with AGP applied :). Oh, I see, thought the android support only referred to Android Instrumented stuff.

@fzhinkin
Copy link
Contributor

fzhinkin commented May 3, 2024

Then it seems like, for now, the only option you have is to use androidx.microbenchmark library (sample project).

// Below is the advice you never asked for, but just in case:

Note that despite the fact that a code written in Kotlin can target both JVM and Android (which is, roughly speaking, JVM bytecode further compiled to DEX), performance characteristics may vary significantly on these platforms, and benchmarking results achieved on JVM may differ from what you may get on Android device (some function A could perform better than some other function B on JVM, but on Android B could become faster than A).

So, if you're interested in measuring the performance of code that will be used in an Android app, I recommend benchmarking it on an Android device.

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

No branches or pull requests

2 participants