From 0df4c62d4f755d8e60197ad46d28bbf658c8173f Mon Sep 17 00:00:00 2001 From: Tristan Hamilton Date: Wed, 10 Feb 2021 22:07:29 +0000 Subject: [PATCH] Move benchmarks to separate subproject --- benchmarks/build.gradle.kts | 43 +++++++++++++++++++ .../michaelbull/result/BindingBenchmark.kt | 20 ++++----- kotlin-result/build.gradle.kts | 28 ------------ settings.gradle.kts | 1 + 4 files changed, 54 insertions(+), 38 deletions(-) rename {kotlin-result/src/jvmBenchmark => benchmarks/src/commonMain}/kotlin/com/github/michaelbull/result/BindingBenchmark.kt (76%) diff --git a/benchmarks/build.gradle.kts b/benchmarks/build.gradle.kts index e69de29..9119257 100644 --- a/benchmarks/build.gradle.kts +++ b/benchmarks/build.gradle.kts @@ -0,0 +1,43 @@ +description = "Benchmarks for kotlin-result." + +plugins { + kotlin("multiplatform") + id("kotlinx.benchmark") + id("org.jetbrains.kotlin.plugin.allopen") +} + +allOpen { + annotation("org.openjdk.jmh.annotations.State") + annotation("org.openjdk.jmh.annotations.BenchmarkMode") +} + +benchmark { + targets { + register("jvm") + // TODO: enable js benchmarking once https://github.com/Kotlin/kotlinx-benchmark/issues/28 is fixed. + // register("js") + } +} + +kotlin { + jvm { + compilations.all { + kotlinOptions { + jvmTarget = "1.8" + } + } + } + + js { + nodejs() + } + + sourceSets { + val commonMain by getting { + dependencies { + implementation(project(":kotlin-result")) + implementation("org.jetbrains.kotlinx:kotlinx.benchmark.runtime:${Versions.kotlinBenchmark}") + } + } + } +} diff --git a/kotlin-result/src/jvmBenchmark/kotlin/com/github/michaelbull/result/BindingBenchmark.kt b/benchmarks/src/commonMain/kotlin/com/github/michaelbull/result/BindingBenchmark.kt similarity index 76% rename from kotlin-result/src/jvmBenchmark/kotlin/com/github/michaelbull/result/BindingBenchmark.kt rename to benchmarks/src/commonMain/kotlin/com/github/michaelbull/result/BindingBenchmark.kt index 729e3d1..37b21ff 100644 --- a/kotlin-result/src/jvmBenchmark/kotlin/com/github/michaelbull/result/BindingBenchmark.kt +++ b/benchmarks/src/commonMain/kotlin/com/github/michaelbull/result/BindingBenchmark.kt @@ -1,16 +1,17 @@ package com.github.michaelbull.result -import org.openjdk.jmh.annotations.Benchmark -import org.openjdk.jmh.annotations.BenchmarkMode -import org.openjdk.jmh.annotations.Mode -import org.openjdk.jmh.annotations.OutputTimeUnit -import org.openjdk.jmh.annotations.Scope -import org.openjdk.jmh.annotations.State -import org.openjdk.jmh.infra.Blackhole -import java.util.concurrent.TimeUnit +import kotlinx.benchmark.BenchmarkMode +import kotlinx.benchmark.Mode +import kotlinx.benchmark.OutputTimeUnit +import kotlinx.benchmark.BenchmarkTimeUnit +import kotlinx.benchmark.Benchmark +import kotlinx.benchmark.Blackhole +import kotlinx.benchmark.State +import kotlinx.benchmark.Scope +@State(Scope.Benchmark) @BenchmarkMode(Mode.Throughput) -@OutputTimeUnit(TimeUnit.MILLISECONDS) +@OutputTimeUnit(BenchmarkTimeUnit.MILLISECONDS) class BindingBenchmark { private object Error @@ -59,7 +60,6 @@ class BindingBenchmark { blackhole.consume(result) } - @State(Scope.Thread) private companion object { private fun provideX(): Result = Ok(1) private fun provideY(): Result = Ok(2) diff --git a/kotlin-result/build.gradle.kts b/kotlin-result/build.gradle.kts index 4dc9a4f..453338e 100644 --- a/kotlin-result/build.gradle.kts +++ b/kotlin-result/build.gradle.kts @@ -3,27 +3,10 @@ description = "A Result monad for modelling success or failure operations." plugins { `maven-publish` kotlin("multiplatform") - id("org.jetbrains.kotlin.plugin.allopen") - id("kotlinx.benchmark") -} - -allOpen { - annotation("org.openjdk.jmh.annotations.State") - annotation("org.openjdk.jmh.annotations.BenchmarkMode") -} - -sourceSets.create("benchmark") - -benchmark { - targets { - register("jvmBenchmark") - } } kotlin { jvm { - withJava() - compilations.all { kotlinOptions { jvmTarget = "1.8" @@ -45,8 +28,6 @@ kotlin { } } - val jvmMain by getting - val jvmTest by getting { dependencies { implementation(kotlin("test-junit")) @@ -54,15 +35,6 @@ kotlin { } } - val jvmBenchmark by getting { - dependsOn(jvmMain) - dependencies { - implementation("org.jetbrains.kotlinx:kotlinx.benchmark.runtime:${Versions.kotlinBenchmark}") - } - } - - val jsMain by getting - val jsTest by getting { dependencies { implementation(kotlin("test-js")) diff --git a/settings.gradle.kts b/settings.gradle.kts index 5242700..3f77e06 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,7 @@ rootProject.name = "kotlin-result" include( + "benchmarks", "example", "kotlin-result", "kotlin-result-coroutines"