ronjunevaldoz/kmp-agent-skills/kmp-benchmark
Claude Code and agent skill by ronjunevaldoz/kmp-agent-skills
- community
Checking that the SKILL.md file is still in the repository.
Sets up kotlinx-benchmark for Kotlin Multiplatform performance measurement. Covers: Gradle plugin + allopen wiring, a separate benchmark source set (never mixed into commonMain/commonTest), @State/@Benchmark/@Setup/@TearDown conventions, per-target registration (JVM/Native/JS/Wasm), running benchmarks, and reading JSON/CSV output. Use this whenever a performance claim needs a real number instead of a guess — this is the "profile first" step the kmp-expert performance decision tree routes to whe…
Install
npx vskill@latest install ronjunevaldoz/kmp-agent-skills/kmp-benchmarkSKILL.md
The same SKILL.md was published earlier as ronjunevaldoz/kmp-agent-skills/kmp-benchmark.
When to Use This Skill
Use when you need to:
- Get a real, reproducible number before claiming a change "improves performance"
- Compare two implementations of the same function (e.g. two JSON parsers, two collection strategies)
- Track a regression across releases with a committed baseline
- Answer
kmp-expert's performance decision tree fallback: "profile first
to get a concrete target"
Trigger keywords: benchmark, microbenchmark, kotlinx-benchmark, performance number, measure performance, profile this, @Benchmark, JMH, is this faster, compare performance, performance regression, benchmark baseline.
Freshness rule: kotlinx-benchmark version, the allopen annotation target, and per-target registration syntax change between releases — recheck the kotlinx-benchmark docs before pinning versions or copying setup code from this skill.
Recommendation First
Default to a dedicated `benchmark` source set, never commonMain or commonTest, using kotlinx.benchmark.* annotations (not org.openjdk.jmh.annotations.* directly) so the same benchmark compiles across every registered target, not just JVM.
Why:
- A benchmark source set that
associateWiththe main compilation gets internal-API
access without shipping benchmark code (or its JMH-generated subclasses) in the real artifact
kotlinx.benchmark.State/@Benchmarkare KMP-portable;org.openjdk.jmh.annotations.*
only compiles on the JVM target — using JMH's own annotations silently locks the benchmark to one target
- Kotlin classes are
finalby default; JMH-style benchmarking needs the class open to
generate subclasses — allopen handles this without hand-adding open everywhere
Prerequisites
- Project scaffolded with
kmp-feature-scaffold - Kotlin 2.2.0+, Gradle 8+
- A concrete function/class to measure — never scaffold a benchmark module speculatively;
see Common Anti-Patterns
Step 1: Gradle plugin + allopen setup
libs.versions.toml
Module build.gradle.kts
Step 2: Writing a benchmark
Place benchmark files in src/commonBenchmark/kotlin/ (or the platform-specific benchmark source set if the code under test is platform-specific).
Rules:
@State(Scope.Benchmark)— one instance shared across all invocations in a benchmark
run; use Scope.Thread only if the state must not be shared across benchmark threads
@Setup/@TearDown— fixture cost never counts toward the measured result- Name benchmark functions for what they measure (
parseWithKotlinxSerialization), not
generic names (test1, benchmarkA) — the report is only useful if the function name says what was measured
Step 3: Multi-target registration
Register one benchmark { targets { register(...) } } entry per Kotlin target you actually measure — the registered name must match an existing compilation:
Native and JS results are not directly comparable to JVM — different runtimes, no JIT warmup on Native, different GC (or none). Compare JVM-to-JVM and Native-to-Native; use cross-target numbers only to confirm a target-specific regression, not to rank targets against each other.
Step 4: Running and reading results
Default output is JSON (JMH-compatible format) under build/reports/benchmarks/main/. Configure reportFormat = "csv" in the configurations { named("main") { ... } } block if you want CSV instead.
Where results go in docs — do not paste raw output into a task note. Per kmp-project-docs-maintainer's existing rule: write the canonical comparison table in docs/reference/benchmark-matrix.md (or the nearest durable docs/reference/ page), and keep any task-note summary short with a link back. Commit the benchmark source alongside the result so a future run can reproduce the number.
Common Anti-Patterns
- Using
org.openjdk.jmh.annotations.*directly instead ofkotlinx.benchmark.*— compiles on JVM only, silently breaks Native/JS targets - Putting benchmark code in
commonMainorcommonTest— ships benchmark code (and its JMH-generated subclasses on JVM) in the real artifact; always a dedicated benchmark source set - Measuring fixture setup inside
@Benchmarkinstead of@Setup— the timed result includes work that isn't the thing being measured - Registering every possible target "for completeness" with nothing to actually measure there — extra compile time and CI cost for numbers nobody reads
- Comparing a JVM benchmark result directly against a Native or JS result — different runtimes; only comparable within the same target
- Pasting raw benchmark JSON/CSV into a task note instead of the canonical
docs/reference/benchmark-matrix.mdtable - Running a benchmark once and treating the number as final — rerun with the configured warmup/iteration counts; a single run is noise, not a result
- Scaffolding a benchmark module before there's a concrete function/claim to measure — benchmark the actual bottleneck found via profiling or a real performance complaint, not speculatively
Testing
kotlinx-benchmark output is itself the test signal — there's no separate unit-test layer for a benchmark module. Validate the setup, not the numbers:
./gradlew :module:jvmBenchmarkBenchmarkcompletes without a compile error and
produces a JSON report under build/reports/benchmarks/
- Each
@Benchmarkfunction's name states what it measures @Setupfixture cost is excluded from the reported number (spot-check by comparing
two runs with and without fixture-building moved into @Benchmark temporarily)
- The
docs/reference/benchmark-matrix.mdtable is updated in the same change that adds
or updates a benchmark
Output Style
When asked to benchmark something, respond in this order:
- Confirm there's a concrete function/claim to measure — ask if not (see Anti-Patterns)
- Gradle setup (plugin, allopen, source set) — only the parts not already present
- The
@Benchmarkclass for the specific comparison requested - The run command and where the report lands
- Where the result belongs in docs (
docs/reference/benchmark-matrix.md)
Related Skills
kmp-expert— the "Improve the performance of X" decision tree routes
here when X is unnamed or needs a concrete number before further routing
kmp-project-docs-maintainer— owns thedocs/reference/benchmark-matrix.md
placement rule this skill's output follows
kmp-jni-pro— JNI boundary-crossing cost claims should be backed by
a benchmark from this skill, not an assumption
kmp-code-quality— Detekt's complexity rules flag style smells;
this skill answers whether a change is actually faster, a different question
Changelog
| Date | Change | |
|---|---|---|
| 2026-07-10 | Initial release — kotlinx-benchmark Gradle/allopen setup, dedicated benchmark source set convention, @State/@Benchmark/@Setup/@TearDown usage, multi-target registration, JVM-vs-Native-vs-JS comparability caveat, docs/reference/benchmark-matrix.md placement wiring. Closes the "profile first" dead-end in kmp-expert's performance decision tree. |
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/kmp-benchmark/SKILL.md
Popularity
- Repository stars
- 3
- 7-day trend score
- 0
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ronjunevaldoz/kmp-agent-skills/kmp-benchmark)