在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):Kotlin/kotlinx-benchmark开源软件地址(OpenSource Url):https://github.com/Kotlin/kotlinx-benchmark开源编程语言(OpenSource Language):Kotlin 100.0%开源软件介绍(OpenSource Introduction):
kotlinx.benchmark is a toolkit for running benchmarks for multiplatform code written in Kotlin and running on the following supported targets: JVM, JavaScript and Native. Both Legacy and IR backends are supported for JS, however On JVM JMH is used under the hoods to run benchmarks. This library has a very similar way of defining benchmark methods. Thus, using this library you can run your JMH-based Kotlin/JVM benchmarks on other platforms with minimum modifications, if any at all. RequirementsGradle 6.8 or newer Kotlin 1.7.0 or newer Gradle pluginUse plugin in plugins {
id 'org.jetbrains.kotlinx.benchmark' version '0.4.4'
} For Kotlin/JS specify building kotlin {
js {
nodejs()
…
}
} For Kotlin/JVM code, add For example, if you annotated each of your benchmark classes with @State(Scope.Benchmark)
class Benchmark {
…
} and added the following code to your plugins {
id 'org.jetbrains.kotlin.plugin.allopen'
}
allOpen {
annotation("org.openjdk.jmh.annotations.State")
} then you don't have to make benchmark classes and methods Runtime LibraryYou need a runtime library with annotations and code that will run benchmarks. Enable Maven Central for dependencies lookup: repositories {
mavenCentral()
} Add the runtime to dependencies of the platform source set, e.g.:
ConfigurationIn a benchmark {
targets {
register("jvm")
register("js")
register("native")
}
} This package can also be used for Java and Kotlin/JVM projects. Register a Java sourceSet as a target: benchmark {
targets {
register("main")
}
} To configure benchmarks and create multiple profiles, create a benchmark {
configurations {
main {
// configure default configuration
}
smoke {
// create and configure "smoke" configuration, e.g. with several fast benchmarks to quickly check
// if code changes result in something very wrong, or very right.
}
}
} Available configuration options:
Time units can be NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, or their short variants such as "ms" or "ns". Example: benchmark {
// Create configurations
configurations {
main { // main configuration is created automatically, but you can change its defaults
warmups = 20 // number of warmup iterations
iterations = 10 // number of iterations
iterationTime = 3 // time in seconds per iteration
}
smoke {
warmups = 5 // number of warmup iterations
iterations = 3 // number of iterations
iterationTime = 500 // time in seconds per iteration
iterationTimeUnit = "ms" // time unit for iterationTime, default is seconds
}
}
// Setup targets
targets {
// This one matches compilation base name, e.g. 'jvm', 'jvmTest', etc
register("jvm") {
jmhVersion = "1.21" // available only for JVM compilations & Java source sets
}
register("js") {
// Note, that benchmarks.js uses a different approach of minTime & maxTime and run benchmarks
// until results are stable. We estimate minTime as iterationTime and maxTime as iterationTime*iterations
}
register("native")
}
} Separate source sets for benchmarksOften you want to have benchmarks in the same project, but separated from main code, much like tests. Here is how: Define source set: sourceSets {
benchmarks
} Propagate dependencies and output from dependencies {
benchmarksCompile sourceSets.main.output + sourceSets.main.runtimeClasspath
} You can also add output and compileClasspath from Register benchmark {
targets {
register("benchmarks")
}
} ExamplesThe project contains examples subproject that demonstrates using the library. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论