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

Support benchmarks having @State annotations in parent classes #130

Open
fzhinkin opened this issue Jul 19, 2023 · 2 comments
Open

Support benchmarks having @State annotations in parent classes #130

fzhinkin opened this issue Jul 19, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@fzhinkin
Copy link
Contributor

kotlinx-benchmark requires benchmark classes to be annotated with @State.

It seems reasonable to expect that when there is a base class annotated with @State providing common routines and state for subclasses, and then it should be enough to simply extend that class w/o explicitly annotating leaf class w/ @State.

Here's an example of such code reuse via inheritance from kotlinx-io benchmarks:

@State(Scope.Benchmark)
abstract class BufferRWBenchmarkBase {
    protected val buffer = Buffer()
    @Setup fun setupBuffers() { /* some setup common for all subclasses */ }
}

open class ByteBenchmark : BufferRWBenchmarkBase() {
    @Benchmark fun benchmark(): Byte {
        buffer.writeByte(0x42)
        return buffer.readByte()
    }
}

open class ShortBenchmark : BufferRWBenchmarkBase() {
    @Benchmark fun benchmark(): Short {
        buffer.writeShort(42)
        return buffer.readShort()
    }
}

...

Also, it would be nice to verify that if benchmark-class and its superclass are both annotated w/ @State with the same scope. The condition would be always true now, but may no longer hold in the future.

My expectations regarding State inheritance are based on how it works in JMH, and because that's a different framework it not necessarily should be true for kotlinx-benchmark. However, if the proposal will be rejected, it would be nice to print warning for the classes having @Benchmark-methods, but not annotated w/ the @State.

@fzhinkin fzhinkin added the enhancement New feature or request label Jul 19, 2023
OndrejSliva pushed a commit to OndrejSliva/kotlinx-benchmark that referenced this issue Jan 10, 2024
…in#130)

Bumps [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) from 1.5.0 to 1.5.1.
- [Release notes](https://github.com/dependabot/fetch-metadata/releases)
- [Commits](dependabot/fetch-metadata@v1.5.0...v1.5.1)

---
updated-dependencies:
- dependency-name: dependabot/fetch-metadata
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@07jasjeet
Copy link

Hi! can I pick this one up?

@qurbonzoda
Copy link
Collaborator

@07jasjeet Yes please

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

3 participants