From beeb016a9f78cb6ecff3bb55dafa89fc55a5420a Mon Sep 17 00:00:00 2001 From: "Aleksei.Glushko" Date: Wed, 25 Oct 2023 15:56:05 +0200 Subject: [PATCH] [K/N] Test runtime logging performance overhead --- .../performance/logging/build.gradle.kts | 21 +++++++++++ .../logging/src/main/kotlin/main.kt | 36 +++++++++++++++++++ kotlin-native/performance/settings.gradle | 1 + 3 files changed, 58 insertions(+) create mode 100644 kotlin-native/performance/logging/build.gradle.kts create mode 100644 kotlin-native/performance/logging/src/main/kotlin/main.kt diff --git a/kotlin-native/performance/logging/build.gradle.kts b/kotlin-native/performance/logging/build.gradle.kts new file mode 100644 index 00000000000..7e6bd1bb562 --- /dev/null +++ b/kotlin-native/performance/logging/build.gradle.kts @@ -0,0 +1,21 @@ +import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget + +/* + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ + +plugins { + id("benchmarking") +} + +benchmark { + applicationName = "Logging" + commonSrcDirs = listOf("../../tools/benchmarks/shared/src/main/kotlin/report", "src/main/kotlin", "../shared/src/main/kotlin") + jvmSrcDirs = listOf("../shared/src/main/kotlin-jvm") + nativeSrcDirs = listOf("../shared/src/main/kotlin-native/common") + mingwSrcDirs = listOf("../shared/src/main/kotlin-native/mingw") + posixSrcDirs = listOf("../shared/src/main/kotlin-native/posix") + compilerOpts = listOf("-Xruntime-logs=logging=debug") +} diff --git a/kotlin-native/performance/logging/src/main/kotlin/main.kt b/kotlin-native/performance/logging/src/main/kotlin/main.kt new file mode 100644 index 00000000000..ce030dd597e --- /dev/null +++ b/kotlin-native/performance/logging/src/main/kotlin/main.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.jetbrains.benchmarksLauncher.* + +fun loop() { + for (i in 0..10000) { + Blackhole.consume(i) + } +} + +fun main(args: Array) { + val launcher = object : Launcher() { + override val baseBenchmarksSet: MutableMap = mutableMapOf("Loop" to BenchmarkEntry(::loop)) + } + + BenchmarksRunner.runBenchmarks(args, { arguments: BenchmarkArguments -> + if (arguments is BaseBenchmarkArguments) { + launcher.launch(arguments.warmup, arguments.repeat, arguments.prefix, + arguments.filter, arguments.filterRegex, arguments.verbose) + } else emptyList() + }, benchmarksListAction = launcher::benchmarksListAction) +} diff --git a/kotlin-native/performance/settings.gradle b/kotlin-native/performance/settings.gradle index 9574fa26a61..a9d4993d7a2 100644 --- a/kotlin-native/performance/settings.gradle +++ b/kotlin-native/performance/settings.gradle @@ -22,6 +22,7 @@ include ':numerical' include ':videoplayer' include ':framework' include ':startup' +include ':logging' if (System.getProperty("os.name") == "Mac OS X") { include ':objcinterop' include ':swiftinterop'