forked from Kotlin/kotlinx-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support debug build configuration for K/N (Kotlin#225)
Adds a build type setting to the NativeBenchmarkTarget to provide the ability to test debug builds. Fixes Kotlin#189
- Loading branch information
1 parent
875ec08
commit 7950a87
Showing
8 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
integration/src/test/kotlin/kotlinx/benchmark/integration/KotlinNativeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package kotlinx.benchmark.integration | ||
|
||
import org.junit.Test | ||
|
||
class KotlinNativeTest : GradleTest() { | ||
@Test | ||
fun debugBenchmarkTest() { | ||
project("kotlin-native", true).let { runner -> | ||
val target = "native" | ||
val capitalizedTarget = target.replaceFirstChar { it.uppercaseChar() } | ||
|
||
runner.run(":${target}BenchmarkGenerate") | ||
runner.run(":compile${capitalizedTarget}BenchmarkKotlin${capitalizedTarget}") | ||
runner.run(":${capitalizedTarget}Benchmark") | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
integration/src/test/resources/templates/kotlin-native/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType | ||
import org.jetbrains.kotlin.konan.target.KonanTarget | ||
import org.jetbrains.kotlin.konan.target.HostManager | ||
|
||
kotlin { | ||
if (HostManager.hostIsLinux) linuxX64('native') | ||
if (HostManager.hostIsMingw) mingwX64('native') | ||
if (HostManager.host == KonanTarget.MACOS_ARM64.INSTANCE) macosArm64('native') | ||
if (HostManager.host == KonanTarget.MACOS_X64.INSTANCE) macosX64('native') | ||
|
||
sourceSets { | ||
commonMain { | ||
dependencies { | ||
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.5.0-SNAPSHOT") | ||
} | ||
} | ||
nativeMain { } | ||
} | ||
} | ||
|
||
benchmark { | ||
targets { | ||
register("native") { | ||
buildType = NativeBuildType.DEBUG | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
integration/src/test/resources/templates/kotlin-native/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.gradle.jvmargs=-Xmx2g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 |
15 changes: 15 additions & 0 deletions
15
...ation/src/test/resources/templates/kotlin-native/src/commonMain/kotlin/CommonBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package test | ||
|
||
import kotlinx.benchmark.* | ||
import kotlin.math.* | ||
|
||
@State(Scope.Benchmark) | ||
@Measurement(iterations = 3, time = 1, timeUnit = BenchmarkTimeUnit.SECONDS) | ||
@OutputTimeUnit(BenchmarkTimeUnit.MILLISECONDS) | ||
@BenchmarkMode(Mode.Throughput) | ||
open class CommonBenchmark { | ||
@Benchmark | ||
open fun mathBenchmark(): Double { | ||
return log(sqrt(3.0) * cos(3.0), 2.0) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ration/src/test/resources/templates/kotlin-native/src/nativeMain/kotlin/DebugBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package test | ||
|
||
import kotlinx.benchmark.* | ||
import kotlin.native.Platform | ||
|
||
@State(Scope.Benchmark) | ||
@Measurement(iterations = 3, time = 1, timeUnit = BenchmarkTimeUnit.SECONDS) | ||
@OutputTimeUnit(BenchmarkTimeUnit.MILLISECONDS) | ||
@BenchmarkMode(Mode.Throughput) | ||
open class DebugBenchmark { | ||
@Benchmark | ||
@OptIn(kotlin.experimental.ExperimentalNativeApi::class) | ||
open fun debugBenchmark(): String { | ||
return if (Platform.isDebugBinary) "Debug Benchmark" | ||
else error("Not a debug binary") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters