From 6c24e9091d3f8e6c0119f806f520b0b880efa3dc Mon Sep 17 00:00:00 2001 From: LepilkinaElena Date: Tue, 31 Mar 2020 12:16:56 +0300 Subject: [PATCH] Refactor new type of benchmarks and support running on JVM in new mode (#4041) --- .../kotlin/BenchmarkRepeatingType.kt | 6 + .../kotlin/org/jetbrains/kotlin/RunJvmTask.kt | 108 +- .../jetbrains/kotlin/RunKotlinNativeTask.kt | 27 +- .../kotlin/benchmark/BenchmarkLogger.kt | 25 + .../kotlin/benchmark/BenchmarkingPlugin.kt | 2 +- .../KotlinNativeBenchmarkingPlugin.kt | 12 +- .../kotlin-jvm/org/jetbrains/ring/UtilsJVM.kt | 18 - .../kotlin-native/org/jetbrains/ring/Utils.kt | 19 - .../ring/DefaultArgumentBenchmark.kt | 1 + .../org/jetbrains/ring/ElvisBenchmark.kt | 1 + .../org/jetbrains/ring/LambdaBenchmark.kt | 2 + .../ring/LinkedListWithAtomicsBenchmark.kt | 2 + .../org/jetbrains/ring/MatrixMapBenchmark.kt | 3 +- .../org/jetbrains/ring/SingletonBenchmark.kt | 1 + .../org/jetbrains/ring/StringBenchmark.kt | 2 + .../org/jetbrains/ring/SwitchBenchmark.kt | 1 + .../main/kotlin/org/jetbrains/ring/Utils.kt | 10 - .../org/jetbrains/benchmarksLauncher/Utils.kt | 16 + .../org/jetbrains/benchmarksLauncher/Utils.kt | 17 + .../BenchmarksCollection.kt | 20 +- .../org/jetbrains/benchmarksLauncher/Utils.kt | 10 + .../jetbrains/benchmarksLauncher/launcher.kt | 60 +- performance/startup/build.gradle.kts | 11 +- .../kotlin-jvm/org/jetbrains/startup/Utils.kt | 16 - .../org/jetbrains/startup/Utils.kt | 17 - .../startup/SingletonInitBenchmark.kt | 1021 ++++++++--------- .../kotlin/org/jetbrains/startup/Utils.kt | 13 - 27 files changed, 739 insertions(+), 702 deletions(-) create mode 100644 build-tools/src/main/kotlin/org/jetbrains/kotlin/BenchmarkRepeatingType.kt create mode 100644 build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/BenchmarkLogger.kt delete mode 100644 performance/startup/src/main/kotlin-jvm/org/jetbrains/startup/Utils.kt delete mode 100644 performance/startup/src/main/kotlin-native/org/jetbrains/startup/Utils.kt delete mode 100644 performance/startup/src/main/kotlin/org/jetbrains/startup/Utils.kt diff --git a/build-tools/src/main/kotlin/org/jetbrains/kotlin/BenchmarkRepeatingType.kt b/build-tools/src/main/kotlin/org/jetbrains/kotlin/BenchmarkRepeatingType.kt new file mode 100644 index 00000000000..6f62eb7afe6 --- /dev/null +++ b/build-tools/src/main/kotlin/org/jetbrains/kotlin/BenchmarkRepeatingType.kt @@ -0,0 +1,6 @@ +package org.jetbrains.kotlin + +enum class BenchmarkRepeatingType { + INTERNAL, // Let the benchmark perform warmups and repeats. + EXTERNAL, // Repeat by relaunching benchmark +} \ No newline at end of file diff --git a/build-tools/src/main/kotlin/org/jetbrains/kotlin/RunJvmTask.kt b/build-tools/src/main/kotlin/org/jetbrains/kotlin/RunJvmTask.kt index 85b2de42755..fcd67fdcb03 100644 --- a/build-tools/src/main/kotlin/org/jetbrains/kotlin/RunJvmTask.kt +++ b/build-tools/src/main/kotlin/org/jetbrains/kotlin/RunJvmTask.kt @@ -5,16 +5,21 @@ package org.jetbrains.kotlin -import groovy.lang.Closure import org.gradle.api.tasks.JavaExec -import org.gradle.api.Task import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.options.Option import org.gradle.api.tasks.Input +import org.jetbrains.kotlin.benchmark.LogLevel +import org.jetbrains.kotlin.benchmark.Logger +import org.jetbrains.report.json.* +import java.io.ByteArrayOutputStream import java.io.File -open class RunJvmTask : JavaExec() { - var outputFileName: String? = null +data class ExecParameters(val warmupCount: Int, val repeatCount: Int, + val filterArgs: List, val filterRegexArgs: List, + val verbose: Boolean, val outputFileName: String?) + +open class RunJvmTask: JavaExec() { @Input @Option(option = "filter", description = "Benchmarks to run (comma-separated)") var filter: String = "" @@ -24,24 +29,97 @@ open class RunJvmTask : JavaExec() { @Input @Option(option = "verbose", description = "Verbose mode of running benchmarks") var verbose: Boolean = false + @Input + var warmupCount: Int = 0 + @Input + var repeatCount: Int = 0 + @Input + var repeatingType = BenchmarkRepeatingType.INTERNAL + @Input + var outputFileName: String? = null - @JvmOverloads - private fun executeTask(output: java.io.OutputStream? = null) { - val filterArgs = filter.splitCommaSeparatedOption("-f") - val filterRegexArgs = filterRegex.splitCommaSeparatedOption("-fr") - args(filterArgs) - args(filterRegexArgs) - if (verbose) { + private var predefinedArgs: List = emptyList() + + private fun executeTask(execParameters: ExecParameters): String { + // Firstly clean arguments. + setArgs(emptyList()) + args(predefinedArgs) + args(execParameters.filterArgs) + args(execParameters.filterRegexArgs) + args("-w", execParameters.warmupCount) + args("-r", execParameters.repeatCount) + if (execParameters.verbose) { args("-v") } + execParameters.outputFileName?.let { args("-o", outputFileName) } + standardOutput = ByteArrayOutputStream() super.exec() + return standardOutput.toString() + } + + private fun getBenchmarksList(filterArgs: List, filterRegexArgs: List): List { + // Firstly clean arguments. + setArgs(emptyList()) + args("list") + standardOutput = ByteArrayOutputStream() + super.exec() + val benchmarks = standardOutput.toString().lines() + val regexes = filterRegexArgs.map { it.toRegex() } + return if (filterArgs.isNotEmpty() || regexes.isNotEmpty()) { + benchmarks.filter { benchmark -> benchmark in filterArgs || regexes.any { it.matches(benchmark) } } + } else benchmarks.filter { !it.isEmpty() } + } + + private fun execSeparateBenchmarkRepeatedly(benchmark: String): List { + // Logging with application should be done only in case it controls running benchmarks itself. + // Although it's a responsibility of gradle task. + val logger = if (verbose) Logger(LogLevel.DEBUG) else Logger() + logger.log("Warm up iterations for benchmark $benchmark\n") + for (i in 0.until(warmupCount)) { + executeTask(ExecParameters(0, 1, listOf("-f", benchmark), + emptyList(), false, null)) + } + val result = mutableListOf() + logger.log("Running benchmark $benchmark ") + for (i in 0.until(repeatCount)) { + logger.log(".", usePrefix = false) + val benchmarkReport = JsonTreeParser.parse( + executeTask(ExecParameters(0, 1, listOf("-f", benchmark), + emptyList(), false, null) + ).removePrefix("[").removeSuffix("]") + ).jsonObject + val modifiedBenchmarkReport = JsonObject(HashMap(benchmarkReport.content).apply { + put("repeat", JsonLiteral(i)) + put("warmup", JsonLiteral(warmupCount)) + }) + result.add(modifiedBenchmarkReport.toString()) + } + logger.log("\n", usePrefix = false) + return result + } + + private fun execBenchmarksRepeatedly(filterArgs: List, filterRegexArgs: List) { + val benchmarksToRun = getBenchmarksList(filterArgs, filterRegexArgs) + val results = benchmarksToRun.flatMap { benchmark -> + execSeparateBenchmarkRepeatedly(benchmark) + } + File(outputFileName).printWriter().use { out -> + out.println("[${results.joinToString(",")}]") + } } @TaskAction override fun exec() { - if (outputFileName != null) - File(outputFileName).outputStream().use { output -> executeTask(output) } - else - executeTask() + assert(outputFileName != null) { "Output file name should be always set" } + predefinedArgs = args ?: emptyList() + val filterArgs = filter.splitCommaSeparatedOption("-f") + val filterRegexArgs = filterRegex.splitCommaSeparatedOption("-fr") + when (repeatingType) { + BenchmarkRepeatingType.INTERNAL -> executeTask( + ExecParameters(warmupCount, repeatCount, filterArgs, filterRegexArgs, verbose, outputFileName) + ) + BenchmarkRepeatingType.EXTERNAL -> execBenchmarksRepeatedly(filterArgs, filterRegexArgs) + } + } } \ No newline at end of file diff --git a/build-tools/src/main/kotlin/org/jetbrains/kotlin/RunKotlinNativeTask.kt b/build-tools/src/main/kotlin/org/jetbrains/kotlin/RunKotlinNativeTask.kt index a174a4b9d5c..f4e4c03ac27 100644 --- a/build-tools/src/main/kotlin/org/jetbrains/kotlin/RunKotlinNativeTask.kt +++ b/build-tools/src/main/kotlin/org/jetbrains/kotlin/RunKotlinNativeTask.kt @@ -7,7 +7,8 @@ package org.jetbrains.kotlin import org.gradle.api.DefaultTask import org.gradle.api.Task -import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink +import org.jetbrains.kotlin.benchmark.Logger +import org.jetbrains.kotlin.benchmark.LogLevel import org.jetbrains.report.json.* import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.options.Option @@ -15,15 +16,12 @@ import org.gradle.api.tasks.Input import java.io.ByteArrayOutputStream import java.io.File import javax.inject.Inject +import kotlin.collections.HashMap open class RunKotlinNativeTask @Inject constructor(private val linkTask: Task, private val executable: String, private val outputFileName: String ) : DefaultTask() { - enum class RepeatingType { - INTERNAL, // Let the benchmark perform warmups and repeats. - EXTERNAL, // Repeat by relaunching benchmark - } @Input @Option(option = "filter", description = "Benchmarks to run (comma-separated)") @@ -39,7 +37,7 @@ open class RunKotlinNativeTask @Inject constructor(private val linkTask: Task, @Input var repeatCount: Int = 0 @Input - var repeatingType = RepeatingType.INTERNAL + var repeatingType = BenchmarkRepeatingType.INTERNAL private val argumentsList = mutableListOf() @@ -62,7 +60,9 @@ open class RunKotlinNativeTask @Inject constructor(private val linkTask: Task, it.executable = executable it.args(argumentsList) it.args("-f", benchmark) - if (verbose) { + // Logging with application should be done only in case it controls running benchmarks itself. + // Although it's a responsibility of gradle task. + if (verbose && repeatingType == BenchmarkRepeatingType.INTERNAL) { it.args("-v") } it.args("-w", warmupCount.toString()) @@ -73,11 +73,15 @@ open class RunKotlinNativeTask @Inject constructor(private val linkTask: Task, } private fun execBenchmarkRepeatedly(benchmark: String, warmupCount: Int, repeatCount: Int) : List { - for (i in 0..warmupCount) { + val logger = if (verbose) Logger(LogLevel.DEBUG) else Logger() + logger.log("Warm up iterations for benchmark $benchmark\n") + for (i in 0.until(warmupCount)) { execBenchmarkOnce(benchmark, 0, 1) } val result = mutableListOf() - for (i in 0..repeatCount) { + logger.log("Running benchmark $benchmark ") + for (i in 0.until(repeatCount)) { + logger.log(".", usePrefix = false) val benchmarkReport = JsonTreeParser.parse(execBenchmarkOnce(benchmark, 0, 1)).jsonObject val modifiedBenchmarkReport = JsonObject(HashMap(benchmarkReport.content).apply { put("repeat", JsonLiteral(i)) @@ -85,6 +89,7 @@ open class RunKotlinNativeTask @Inject constructor(private val linkTask: Task, }) result.add(modifiedBenchmarkReport.toString()) } + logger.log("\n", usePrefix = false) return result } @@ -106,8 +111,8 @@ open class RunKotlinNativeTask @Inject constructor(private val linkTask: Task, val results = benchmarksToRun.flatMap { benchmark -> when (repeatingType) { - RepeatingType.INTERNAL -> listOf(execBenchmarkOnce(benchmark, warmupCount, repeatCount)) - RepeatingType.EXTERNAL -> execBenchmarkRepeatedly(benchmark, warmupCount, repeatCount) + BenchmarkRepeatingType.INTERNAL -> listOf(execBenchmarkOnce(benchmark, warmupCount, repeatCount)) + BenchmarkRepeatingType.EXTERNAL -> execBenchmarkRepeatedly(benchmark, warmupCount, repeatCount) } } diff --git a/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/BenchmarkLogger.kt b/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/BenchmarkLogger.kt new file mode 100644 index 00000000000..4e13ca68b79 --- /dev/null +++ b/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/BenchmarkLogger.kt @@ -0,0 +1,25 @@ +package org.jetbrains.kotlin.benchmark + +import java.text.SimpleDateFormat +import java.util.* + +enum class LogLevel { DEBUG, OFF } + +class Logger(val level: LogLevel = LogLevel.OFF) { + private fun printStderr(message: String) { + System.err.print(message) + } + + private fun currentTime(): String = + SimpleDateFormat("HH:mm:ss").format(Date()) + + fun log(message: String, messageLevel: LogLevel = LogLevel.DEBUG, usePrefix: Boolean = true) { + if (messageLevel == level) { + if (usePrefix) { + printStderr("[$level][${currentTime()}] $message") + } else { + printStderr("$message") + } + } + } +} \ No newline at end of file diff --git a/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/BenchmarkingPlugin.kt b/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/BenchmarkingPlugin.kt index 87854d00884..5aede9220c1 100644 --- a/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/BenchmarkingPlugin.kt +++ b/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/BenchmarkingPlugin.kt @@ -70,7 +70,7 @@ open class BenchmarkExtension @Inject constructor(val project: Project) { var linkerOpts: Collection = emptyList() var compilerOpts: List = emptyList() var buildType: NativeBuildType = NativeBuildType.RELEASE - var repeatingType: RunKotlinNativeTask.RepeatingType = RunKotlinNativeTask.RepeatingType.INTERNAL + var repeatingType: BenchmarkRepeatingType = BenchmarkRepeatingType.INTERNAL val dependencies: BenchmarkDependencies = BenchmarkDependencies() diff --git a/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/KotlinNativeBenchmarkingPlugin.kt b/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/KotlinNativeBenchmarkingPlugin.kt index 22aaabf5d3d..b639a309b94 100644 --- a/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/KotlinNativeBenchmarkingPlugin.kt +++ b/build-tools/src/main/kotlin/org/jetbrains/kotlin/benchmark/KotlinNativeBenchmarkingPlugin.kt @@ -8,7 +8,6 @@ import org.jetbrains.kotlin.* import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.gradle.plugin.mpp.Executable import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType import org.jetbrains.kotlin.konan.target.HostManager import javax.inject.Inject import kotlin.reflect.KClass @@ -76,12 +75,11 @@ open class KotlinNativeBenchmarkingPlugin: BenchmarkingPlugin() { // Specify settings configured by a user in the benchmark extension. afterEvaluate { - task.args( - "-w", jvmWarmup, - "-r", attempts, - "-o", buildDir.resolve(jvmBenchResults), - "-p", "${benchmark.applicationName}::" - ) + task.args("-p", "${benchmark.applicationName}::") + task.warmupCount = jvmWarmup + task.repeatCount = attempts + task.outputFileName = buildDir.resolve(jvmBenchResults).absolutePath + task.repeatingType = benchmark.repeatingType } } } diff --git a/performance/ring/src/main/kotlin-jvm/org/jetbrains/ring/UtilsJVM.kt b/performance/ring/src/main/kotlin-jvm/org/jetbrains/ring/UtilsJVM.kt index 1be74679e54..6f4742bab4b 100644 --- a/performance/ring/src/main/kotlin-jvm/org/jetbrains/ring/UtilsJVM.kt +++ b/performance/ring/src/main/kotlin-jvm/org/jetbrains/ring/UtilsJVM.kt @@ -19,24 +19,6 @@ package org.jetbrains.ring import java.util.concurrent.atomic.AtomicReferenceFieldUpdater import java.util.concurrent.locks.ReentrantLock -//-----------------------------------------------------------------------------// - -actual class Random actual constructor() { - actual companion object { - actual var seedInt = 0 - actual fun nextInt(boundary: Int): Int { - seedInt = (3 * seedInt + 11) % boundary - return seedInt - } - - actual var seedDouble: Double = 0.1 - actual fun nextDouble(boundary: Double): Double { - seedDouble = (7.0 * seedDouble + 7.0) % boundary - return seedDouble - } - } -} - internal var interceptor: AtomicOperationInterceptor = DefaultInterceptor private set private val interceptorLock = ReentrantLock() diff --git a/performance/ring/src/main/kotlin-native/org/jetbrains/ring/Utils.kt b/performance/ring/src/main/kotlin-native/org/jetbrains/ring/Utils.kt index 3beb14e75f2..113db5e1c23 100644 --- a/performance/ring/src/main/kotlin-native/org/jetbrains/ring/Utils.kt +++ b/performance/ring/src/main/kotlin-native/org/jetbrains/ring/Utils.kt @@ -20,25 +20,6 @@ import kotlin.native.concurrent.FreezableAtomicReference as KAtomicRef import kotlin.native.concurrent.isFrozen import kotlin.native.concurrent.freeze -//-----------------------------------------------------------------------------// - -actual class Random actual constructor() { - @kotlin.native.ThreadLocal - actual companion object { - actual var seedInt = 0 - actual fun nextInt(boundary: Int): Int { - seedInt = (3 * seedInt + 11) % boundary - return seedInt - } - - actual var seedDouble: Double = 0.1 - actual fun nextDouble(boundary: Double): Double { - seedDouble = (7.0 * seedDouble + 7.0) % boundary - return seedDouble - } - } -} - public actual class AtomicRef constructor(@PublishedApi internal val a: KAtomicRef) { public actual inline var value: T get() = a.value diff --git a/performance/ring/src/main/kotlin/org/jetbrains/ring/DefaultArgumentBenchmark.kt b/performance/ring/src/main/kotlin/org/jetbrains/ring/DefaultArgumentBenchmark.kt index 8b99894fa22..ae5594fe863 100644 --- a/performance/ring/src/main/kotlin/org/jetbrains/ring/DefaultArgumentBenchmark.kt +++ b/performance/ring/src/main/kotlin/org/jetbrains/ring/DefaultArgumentBenchmark.kt @@ -15,6 +15,7 @@ */ package org.jetbrains.ring +import org.jetbrains.benchmarksLauncher.Random /** * Created by Mikhail.Glukhikh on 10/03/2015. diff --git a/performance/ring/src/main/kotlin/org/jetbrains/ring/ElvisBenchmark.kt b/performance/ring/src/main/kotlin/org/jetbrains/ring/ElvisBenchmark.kt index 76e14666fad..2d09c581679 100644 --- a/performance/ring/src/main/kotlin/org/jetbrains/ring/ElvisBenchmark.kt +++ b/performance/ring/src/main/kotlin/org/jetbrains/ring/ElvisBenchmark.kt @@ -17,6 +17,7 @@ package org.jetbrains.ring import org.jetbrains.benchmarksLauncher.Blackhole +import org.jetbrains.benchmarksLauncher.Random open class ElvisBenchmark { diff --git a/performance/ring/src/main/kotlin/org/jetbrains/ring/LambdaBenchmark.kt b/performance/ring/src/main/kotlin/org/jetbrains/ring/LambdaBenchmark.kt index 4d99367e235..eb03c5cfd60 100644 --- a/performance/ring/src/main/kotlin/org/jetbrains/ring/LambdaBenchmark.kt +++ b/performance/ring/src/main/kotlin/org/jetbrains/ring/LambdaBenchmark.kt @@ -16,6 +16,8 @@ package org.jetbrains.ring +import org.jetbrains.benchmarksLauncher.Random + var globalAddendum = 0 open class LambdaBenchmark { diff --git a/performance/ring/src/main/kotlin/org/jetbrains/ring/LinkedListWithAtomicsBenchmark.kt b/performance/ring/src/main/kotlin/org/jetbrains/ring/LinkedListWithAtomicsBenchmark.kt index 24fcdc7ae90..2015191b2fd 100644 --- a/performance/ring/src/main/kotlin/org/jetbrains/ring/LinkedListWithAtomicsBenchmark.kt +++ b/performance/ring/src/main/kotlin/org/jetbrains/ring/LinkedListWithAtomicsBenchmark.kt @@ -5,6 +5,8 @@ package org.jetbrains.ring +import org.jetbrains.benchmarksLauncher.Random + class ChunkBuffer(var readPosition: Int, var writePosition: Int = readPosition + Random.nextInt(50)) { private val nextRef: AtomicRef = atomic(null) diff --git a/performance/ring/src/main/kotlin/org/jetbrains/ring/MatrixMapBenchmark.kt b/performance/ring/src/main/kotlin/org/jetbrains/ring/MatrixMapBenchmark.kt index 9ac03b6abd0..c308d85e8b8 100644 --- a/performance/ring/src/main/kotlin/org/jetbrains/ring/MatrixMapBenchmark.kt +++ b/performance/ring/src/main/kotlin/org/jetbrains/ring/MatrixMapBenchmark.kt @@ -16,7 +16,8 @@ package org.jetbrains.ring -import org.jetbrains.ring.BENCHMARK_SIZE +import org.jetbrains.benchmarksLauncher.Blackhole +import org.jetbrains.benchmarksLauncher.Random /** * This class emulates matrix behaviour using a hash map as its implementation diff --git a/performance/ring/src/main/kotlin/org/jetbrains/ring/SingletonBenchmark.kt b/performance/ring/src/main/kotlin/org/jetbrains/ring/SingletonBenchmark.kt index 6a881fc8754..104b452bc86 100644 --- a/performance/ring/src/main/kotlin/org/jetbrains/ring/SingletonBenchmark.kt +++ b/performance/ring/src/main/kotlin/org/jetbrains/ring/SingletonBenchmark.kt @@ -6,6 +6,7 @@ package org.jetbrains.ring import org.jetbrains.benchmarksLauncher.Blackhole +import org.jetbrains.benchmarksLauncher.Random private object A { val a = Random.nextInt(100) diff --git a/performance/ring/src/main/kotlin/org/jetbrains/ring/StringBenchmark.kt b/performance/ring/src/main/kotlin/org/jetbrains/ring/StringBenchmark.kt index 2bf6ab0f254..257c5055d8b 100644 --- a/performance/ring/src/main/kotlin/org/jetbrains/ring/StringBenchmark.kt +++ b/performance/ring/src/main/kotlin/org/jetbrains/ring/StringBenchmark.kt @@ -16,6 +16,8 @@ package org.jetbrains.ring +import org.jetbrains.benchmarksLauncher.Random + open class StringBenchmark { private var _data: ArrayList? = null val data: ArrayList diff --git a/performance/ring/src/main/kotlin/org/jetbrains/ring/SwitchBenchmark.kt b/performance/ring/src/main/kotlin/org/jetbrains/ring/SwitchBenchmark.kt index 42b33629b2d..463cb2b8ce9 100644 --- a/performance/ring/src/main/kotlin/org/jetbrains/ring/SwitchBenchmark.kt +++ b/performance/ring/src/main/kotlin/org/jetbrains/ring/SwitchBenchmark.kt @@ -17,6 +17,7 @@ package org.jetbrains.ring import org.jetbrains.benchmarksLauncher.Blackhole +import org.jetbrains.benchmarksLauncher.Random val SPARSE_SWITCH_CASES = intArrayOf(11, 29, 47, 71, 103, 149, 175, 227, 263, 307, diff --git a/performance/ring/src/main/kotlin/org/jetbrains/ring/Utils.kt b/performance/ring/src/main/kotlin/org/jetbrains/ring/Utils.kt index 837c46b290f..ea1c4439b86 100644 --- a/performance/ring/src/main/kotlin/org/jetbrains/ring/Utils.kt +++ b/performance/ring/src/main/kotlin/org/jetbrains/ring/Utils.kt @@ -18,16 +18,6 @@ package org.jetbrains.ring const val BENCHMARK_SIZE = 10000 -expect class Random() { - companion object { - var seedInt: Int - fun nextInt(boundary: Int = 100): Int - - var seedDouble: Double - fun nextDouble(boundary: Double = 100.0): Double - } -} - expect class AtomicRef { /** * Reading/writing this property maps to read/write of volatile variable. diff --git a/performance/shared/src/main/kotlin-jvm/org/jetbrains/benchmarksLauncher/Utils.kt b/performance/shared/src/main/kotlin-jvm/org/jetbrains/benchmarksLauncher/Utils.kt index 1bf91970850..e19e0936965 100644 --- a/performance/shared/src/main/kotlin-jvm/org/jetbrains/benchmarksLauncher/Utils.kt +++ b/performance/shared/src/main/kotlin-jvm/org/jetbrains/benchmarksLauncher/Utils.kt @@ -56,3 +56,19 @@ actual class Blackhole { } } +actual class Random actual constructor() { + actual companion object { + actual var seedInt = 0 + actual fun nextInt(boundary: Int): Int { + seedInt = (3 * seedInt + 11) % boundary + return seedInt + } + + actual var seedDouble: Double = 0.1 + actual fun nextDouble(boundary: Double): Double { + seedDouble = (7.0 * seedDouble + 7.0) % boundary + return seedDouble + } + } +} + diff --git a/performance/shared/src/main/kotlin-native/common/org/jetbrains/benchmarksLauncher/Utils.kt b/performance/shared/src/main/kotlin-native/common/org/jetbrains/benchmarksLauncher/Utils.kt index 000c40c2818..7de36732996 100644 --- a/performance/shared/src/main/kotlin-native/common/org/jetbrains/benchmarksLauncher/Utils.kt +++ b/performance/shared/src/main/kotlin-native/common/org/jetbrains/benchmarksLauncher/Utils.kt @@ -59,4 +59,21 @@ actual class Blackhole { consumer += value.hashCode() } } +} + +actual class Random actual constructor() { + @kotlin.native.ThreadLocal + actual companion object { + actual var seedInt = 0 + actual fun nextInt(boundary: Int): Int { + seedInt = (3 * seedInt + 11) % boundary + return seedInt + } + + actual var seedDouble: Double = 0.1 + actual fun nextDouble(boundary: Double): Double { + seedDouble = (7.0 * seedDouble + 7.0) % boundary + return seedDouble + } + } } \ No newline at end of file diff --git a/performance/shared/src/main/kotlin/org/jetbrains/benchmarksLauncher/BenchmarksCollection.kt b/performance/shared/src/main/kotlin/org/jetbrains/benchmarksLauncher/BenchmarksCollection.kt index 74f6209d16c..71045bccdc3 100644 --- a/performance/shared/src/main/kotlin/org/jetbrains/benchmarksLauncher/BenchmarksCollection.kt +++ b/performance/shared/src/main/kotlin/org/jetbrains/benchmarksLauncher/BenchmarksCollection.kt @@ -18,23 +18,25 @@ package org.jetbrains.benchmarksLauncher import org.jetbrains.report.BenchmarkResult -interface AbstractBenchmarkEntry +interface AbstractBenchmarkEntry { + open val useAutoEvaluatedNumberOfMeasure: Boolean +} class BenchmarkEntryWithInit(val ctor: ()->Any, val lambda: (Any) -> Any?): AbstractBenchmarkEntry { companion object { inline fun create(noinline ctor: ()->T, crossinline lambda: T.() -> Any?) = BenchmarkEntryWithInit(ctor) { (it as T).lambda() } } + + override val useAutoEvaluatedNumberOfMeasure: Boolean = true } -class BenchmarkEntry(val lambda: () -> Any?) : AbstractBenchmarkEntry +open class BenchmarkEntry(val lambda: () -> Any?) : AbstractBenchmarkEntry { + override val useAutoEvaluatedNumberOfMeasure: Boolean = true +} -// Controls warmup and repeats manually. -data class BenchmarkManualResult( - val status: BenchmarkResult.Status, - val value: Any?, - val warmupCount: Int, - val durationsNs: List) -class BenchmarkEntryManual(val lambda: () -> BenchmarkManualResult) : AbstractBenchmarkEntry +class BenchmarkEntryManual(lambda: () -> Any?) : BenchmarkEntry(lambda) { + override val useAutoEvaluatedNumberOfMeasure: Boolean = false +} class BenchmarksCollection(private val benchmarks: MutableMap = mutableMapOf()) : MutableMap by benchmarks diff --git a/performance/shared/src/main/kotlin/org/jetbrains/benchmarksLauncher/Utils.kt b/performance/shared/src/main/kotlin/org/jetbrains/benchmarksLauncher/Utils.kt index a2a03c203ae..bfa1a4fe350 100644 --- a/performance/shared/src/main/kotlin/org/jetbrains/benchmarksLauncher/Utils.kt +++ b/performance/shared/src/main/kotlin/org/jetbrains/benchmarksLauncher/Utils.kt @@ -35,4 +35,14 @@ expect class Blackhole { var consumer: Int fun consume(value: Any) } +} + +expect class Random() { + companion object { + var seedInt: Int + fun nextInt(boundary: Int = 100): Int + + var seedDouble: Double + fun nextDouble(boundary: Double = 100.0): Double + } } \ No newline at end of file diff --git a/performance/shared/src/main/kotlin/org/jetbrains/benchmarksLauncher/launcher.kt b/performance/shared/src/main/kotlin/org/jetbrains/benchmarksLauncher/launcher.kt index ac709086096..1f344a2af66 100644 --- a/performance/shared/src/main/kotlin/org/jetbrains/benchmarksLauncher/launcher.kt +++ b/performance/shared/src/main/kotlin/org/jetbrains/benchmarksLauncher/launcher.kt @@ -67,17 +67,17 @@ abstract class Launcher { } } - fun runBenchmarkRepeatedly(logger: Logger, - numWarmIterations: Int, - numberOfAttempts: Int, - name: String, - recordMeasurement: (RecordTimeMeasurement) -> Unit, - benchmarkInstance: Any?, - benchmark: AbstractBenchmarkEntry) { + fun runBenchmark(logger: Logger, + numWarmIterations: Int, + numberOfAttempts: Int, + name: String, + recordMeasurement: (RecordTimeMeasurement) -> Unit, + benchmark: AbstractBenchmarkEntry) { + val benchmarkInstance = (benchmark as? BenchmarkEntryWithInit)?.ctor?.invoke() logger.log("Warm up iterations for benchmark $name\n") runBenchmark(benchmarkInstance, benchmark, numWarmIterations) var autoEvaluatedNumberOfMeasureIteration = 1 - while (true) { + while (true && benchmark.useAutoEvaluatedNumberOfMeasure) { var j = autoEvaluatedNumberOfMeasureIteration val time = runBenchmark(benchmarkInstance, benchmark, j) if (time >= 100L * 1_000_000) // 100ms @@ -85,7 +85,7 @@ abstract class Launcher { autoEvaluatedNumberOfMeasureIteration *= 2 } logger.log("Running benchmark $name ") - for (k in 0..numberOfAttempts) { + for (k in 0.until(numberOfAttempts)) { logger.log(".", usePrefix = false) var i = autoEvaluatedNumberOfMeasureIteration val time = runBenchmark(benchmarkInstance, benchmark, i) @@ -96,43 +96,6 @@ abstract class Launcher { logger.log("\n", usePrefix = false) } - fun runBenchmark(logger: Logger, - numWarmIterations: Int, - numberOfAttempts: Int, - name: String, - recordMeasurement: (RecordTimeMeasurement) -> Unit, - benchmark: AbstractBenchmarkEntry) { - when (benchmark) { - is BenchmarkEntryWithInit -> { - val benchmarkInstance = benchmark.ctor?.invoke() - runBenchmarkRepeatedly(logger, - numWarmIterations, - numberOfAttempts, - name, - recordMeasurement, - benchmarkInstance, - benchmark) - } - is BenchmarkEntry -> { - runBenchmarkRepeatedly(logger, - numWarmIterations, - numberOfAttempts, - name, - recordMeasurement, - null, - benchmark) - } - is BenchmarkEntryManual -> { - logger.log("Running manual benchmark $name") - val result = benchmark.lambda() - for ((i, durationNs) in result.durationsNs.withIndex()) { - recordMeasurement(RecordTimeMeasurement(result.status, i, result.warmupCount, durationNs)) - } - } - else -> error("unknown benchmark type $benchmark") - } - } - fun launch(numWarmIterations: Int, numberOfAttempts: Int, prefix: String = "", @@ -166,7 +129,10 @@ abstract class Launcher { runBenchmark(logger, numWarmIterations, numberOfAttempts, name, recordMeasurement, benchmark) } catch (e: Throwable) { printStderr("Failure while running benchmark $name: $e\n") - throw e + benchmarkResults.add(BenchmarkResult( + "$prefix$name", BenchmarkResult.Status.FAILED, 0.0, + BenchmarkResult.Metric.EXECUTION_TIME, 0.0, numberOfAttempts, numWarmIterations) + ) } } return benchmarkResults diff --git a/performance/startup/build.gradle.kts b/performance/startup/build.gradle.kts index d3592d98979..5effe87088b 100644 --- a/performance/startup/build.gradle.kts +++ b/performance/startup/build.gradle.kts @@ -1,5 +1,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType import org.jetbrains.kotlin.RunKotlinNativeTask +import org.jetbrains.kotlin.BenchmarkRepeatingType /* * Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license @@ -15,12 +16,12 @@ val defaultBuildType = NativeBuildType.RELEASE benchmark { applicationName = "Startup" commonSrcDirs = listOf("../../tools/benchmarks/shared/src", "src/main/kotlin", "../shared/src/main/kotlin") - jvmSrcDirs = listOf("src/main/kotlin-jvm", "../shared/src/main/kotlin-jvm") - nativeSrcDirs = listOf("src/main/kotlin-native", "../shared/src/main/kotlin-native/common") - mingwSrcDirs = listOf("src/main/kotlin-native", "../shared/src/main/kotlin-native/mingw") - posixSrcDirs = listOf("src/main/kotlin-native", "../shared/src/main/kotlin-native/posix") + 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") buildType = (findProperty("nativeBuildType") as String?)?.let { NativeBuildType.valueOf(it) } ?: defaultBuildType - repeatingType = RunKotlinNativeTask.RepeatingType.EXTERNAL + repeatingType = BenchmarkRepeatingType.EXTERNAL dependencies.common(project(":endorsedLibraries:kotlinx.cli")) } diff --git a/performance/startup/src/main/kotlin-jvm/org/jetbrains/startup/Utils.kt b/performance/startup/src/main/kotlin-jvm/org/jetbrains/startup/Utils.kt deleted file mode 100644 index f1cd8aca044..00000000000 --- a/performance/startup/src/main/kotlin-jvm/org/jetbrains/startup/Utils.kt +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2010-2020 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. - */ - -package org.jetbrains.startup - -actual class Random actual constructor() { - actual companion object { - actual var seedInt = 0 - actual fun nextInt(boundary: Int): Int { - seedInt = (3 * seedInt + 11) % boundary - return seedInt - } - } -} diff --git a/performance/startup/src/main/kotlin-native/org/jetbrains/startup/Utils.kt b/performance/startup/src/main/kotlin-native/org/jetbrains/startup/Utils.kt deleted file mode 100644 index a5032ae2f4b..00000000000 --- a/performance/startup/src/main/kotlin-native/org/jetbrains/startup/Utils.kt +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2010-2020 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. - */ - -package org.jetbrains.startup - -actual class Random actual constructor() { - @kotlin.native.ThreadLocal - actual companion object { - actual var seedInt = 0 - actual fun nextInt(boundary: Int): Int { - seedInt = (3 * seedInt + 11) % boundary - return seedInt - } - } -} diff --git a/performance/startup/src/main/kotlin/org/jetbrains/startup/SingletonInitBenchmark.kt b/performance/startup/src/main/kotlin/org/jetbrains/startup/SingletonInitBenchmark.kt index b26eeec48f1..bbca3561eec 100644 --- a/performance/startup/src/main/kotlin/org/jetbrains/startup/SingletonInitBenchmark.kt +++ b/performance/startup/src/main/kotlin/org/jetbrains/startup/SingletonInitBenchmark.kt @@ -5,8 +5,8 @@ package org.jetbrains.startup -import org.jetbrains.benchmarksLauncher.BenchmarkManualResult import org.jetbrains.benchmarksLauncher.measureNanoTime +import org.jetbrains.benchmarksLauncher.Random import org.jetbrains.report.BenchmarkResult private object A0 { val a = Random.nextInt(100) } @@ -512,518 +512,516 @@ private object A499 { val a = Random.nextInt(100) } private var singletonInitializeRun = false // Benchmark -fun singletonInitialize(): BenchmarkManualResult { +fun singletonInitialize(): Int { if (singletonInitializeRun) { - return BenchmarkManualResult(BenchmarkResult.Status.FAILED, 0, 0, listOf(0.0)) + error("Function singletonInitialize can be called only once.") } singletonInitializeRun = true var total = 0 - val time = measureNanoTime { - total += A0.a - total += A1.a - total += A2.a - total += A3.a - total += A4.a - total += A5.a - total += A6.a - total += A7.a - total += A8.a - total += A9.a - total += A10.a - total += A11.a - total += A12.a - total += A13.a - total += A14.a - total += A15.a - total += A16.a - total += A17.a - total += A18.a - total += A19.a - total += A20.a - total += A21.a - total += A22.a - total += A23.a - total += A24.a - total += A25.a - total += A26.a - total += A27.a - total += A28.a - total += A29.a - total += A30.a - total += A31.a - total += A32.a - total += A33.a - total += A34.a - total += A35.a - total += A36.a - total += A37.a - total += A38.a - total += A39.a - total += A40.a - total += A41.a - total += A42.a - total += A43.a - total += A44.a - total += A45.a - total += A46.a - total += A47.a - total += A48.a - total += A49.a - total += A50.a - total += A51.a - total += A52.a - total += A53.a - total += A54.a - total += A55.a - total += A56.a - total += A57.a - total += A58.a - total += A59.a - total += A60.a - total += A61.a - total += A62.a - total += A63.a - total += A64.a - total += A65.a - total += A66.a - total += A67.a - total += A68.a - total += A69.a - total += A70.a - total += A71.a - total += A72.a - total += A73.a - total += A74.a - total += A75.a - total += A76.a - total += A77.a - total += A78.a - total += A79.a - total += A80.a - total += A81.a - total += A82.a - total += A83.a - total += A84.a - total += A85.a - total += A86.a - total += A87.a - total += A88.a - total += A89.a - total += A90.a - total += A91.a - total += A92.a - total += A93.a - total += A94.a - total += A95.a - total += A96.a - total += A97.a - total += A98.a - total += A99.a - total += A100.a - total += A101.a - total += A102.a - total += A103.a - total += A104.a - total += A105.a - total += A106.a - total += A107.a - total += A108.a - total += A109.a - total += A110.a - total += A111.a - total += A112.a - total += A113.a - total += A114.a - total += A115.a - total += A116.a - total += A117.a - total += A118.a - total += A119.a - total += A120.a - total += A121.a - total += A122.a - total += A123.a - total += A124.a - total += A125.a - total += A126.a - total += A127.a - total += A128.a - total += A129.a - total += A130.a - total += A131.a - total += A132.a - total += A133.a - total += A134.a - total += A135.a - total += A136.a - total += A137.a - total += A138.a - total += A139.a - total += A140.a - total += A141.a - total += A142.a - total += A143.a - total += A144.a - total += A145.a - total += A146.a - total += A147.a - total += A148.a - total += A149.a - total += A150.a - total += A151.a - total += A152.a - total += A153.a - total += A154.a - total += A155.a - total += A156.a - total += A157.a - total += A158.a - total += A159.a - total += A160.a - total += A161.a - total += A162.a - total += A163.a - total += A164.a - total += A165.a - total += A166.a - total += A167.a - total += A168.a - total += A169.a - total += A170.a - total += A171.a - total += A172.a - total += A173.a - total += A174.a - total += A175.a - total += A176.a - total += A177.a - total += A178.a - total += A179.a - total += A180.a - total += A181.a - total += A182.a - total += A183.a - total += A184.a - total += A185.a - total += A186.a - total += A187.a - total += A188.a - total += A189.a - total += A190.a - total += A191.a - total += A192.a - total += A193.a - total += A194.a - total += A195.a - total += A196.a - total += A197.a - total += A198.a - total += A199.a - total += A200.a - total += A201.a - total += A202.a - total += A203.a - total += A204.a - total += A205.a - total += A206.a - total += A207.a - total += A208.a - total += A209.a - total += A210.a - total += A211.a - total += A212.a - total += A213.a - total += A214.a - total += A215.a - total += A216.a - total += A217.a - total += A218.a - total += A219.a - total += A220.a - total += A221.a - total += A222.a - total += A223.a - total += A224.a - total += A225.a - total += A226.a - total += A227.a - total += A228.a - total += A229.a - total += A230.a - total += A231.a - total += A232.a - total += A233.a - total += A234.a - total += A235.a - total += A236.a - total += A237.a - total += A238.a - total += A239.a - total += A240.a - total += A241.a - total += A242.a - total += A243.a - total += A244.a - total += A245.a - total += A246.a - total += A247.a - total += A248.a - total += A249.a - total += A250.a - total += A251.a - total += A252.a - total += A253.a - total += A254.a - total += A255.a - total += A256.a - total += A257.a - total += A258.a - total += A259.a - total += A260.a - total += A261.a - total += A262.a - total += A263.a - total += A264.a - total += A265.a - total += A266.a - total += A267.a - total += A268.a - total += A269.a - total += A270.a - total += A271.a - total += A272.a - total += A273.a - total += A274.a - total += A275.a - total += A276.a - total += A277.a - total += A278.a - total += A279.a - total += A280.a - total += A281.a - total += A282.a - total += A283.a - total += A284.a - total += A285.a - total += A286.a - total += A287.a - total += A288.a - total += A289.a - total += A290.a - total += A291.a - total += A292.a - total += A293.a - total += A294.a - total += A295.a - total += A296.a - total += A297.a - total += A298.a - total += A299.a - total += A300.a - total += A301.a - total += A302.a - total += A303.a - total += A304.a - total += A305.a - total += A306.a - total += A307.a - total += A308.a - total += A309.a - total += A310.a - total += A311.a - total += A312.a - total += A313.a - total += A314.a - total += A315.a - total += A316.a - total += A317.a - total += A318.a - total += A319.a - total += A320.a - total += A321.a - total += A322.a - total += A323.a - total += A324.a - total += A325.a - total += A326.a - total += A327.a - total += A328.a - total += A329.a - total += A330.a - total += A331.a - total += A332.a - total += A333.a - total += A334.a - total += A335.a - total += A336.a - total += A337.a - total += A338.a - total += A339.a - total += A340.a - total += A341.a - total += A342.a - total += A343.a - total += A344.a - total += A345.a - total += A346.a - total += A347.a - total += A348.a - total += A349.a - total += A350.a - total += A351.a - total += A352.a - total += A353.a - total += A354.a - total += A355.a - total += A356.a - total += A357.a - total += A358.a - total += A359.a - total += A360.a - total += A361.a - total += A362.a - total += A363.a - total += A364.a - total += A365.a - total += A366.a - total += A367.a - total += A368.a - total += A369.a - total += A370.a - total += A371.a - total += A372.a - total += A373.a - total += A374.a - total += A375.a - total += A376.a - total += A377.a - total += A378.a - total += A379.a - total += A380.a - total += A381.a - total += A382.a - total += A383.a - total += A384.a - total += A385.a - total += A386.a - total += A387.a - total += A388.a - total += A389.a - total += A390.a - total += A391.a - total += A392.a - total += A393.a - total += A394.a - total += A395.a - total += A396.a - total += A397.a - total += A398.a - total += A399.a - total += A400.a - total += A401.a - total += A402.a - total += A403.a - total += A404.a - total += A405.a - total += A406.a - total += A407.a - total += A408.a - total += A409.a - total += A410.a - total += A411.a - total += A412.a - total += A413.a - total += A414.a - total += A415.a - total += A416.a - total += A417.a - total += A418.a - total += A419.a - total += A420.a - total += A421.a - total += A422.a - total += A423.a - total += A424.a - total += A425.a - total += A426.a - total += A427.a - total += A428.a - total += A429.a - total += A430.a - total += A431.a - total += A432.a - total += A433.a - total += A434.a - total += A435.a - total += A436.a - total += A437.a - total += A438.a - total += A439.a - total += A440.a - total += A441.a - total += A442.a - total += A443.a - total += A444.a - total += A445.a - total += A446.a - total += A447.a - total += A448.a - total += A449.a - total += A450.a - total += A451.a - total += A452.a - total += A453.a - total += A454.a - total += A455.a - total += A456.a - total += A457.a - total += A458.a - total += A459.a - total += A460.a - total += A461.a - total += A462.a - total += A463.a - total += A464.a - total += A465.a - total += A466.a - total += A467.a - total += A468.a - total += A469.a - total += A470.a - total += A471.a - total += A472.a - total += A473.a - total += A474.a - total += A475.a - total += A476.a - total += A477.a - total += A478.a - total += A479.a - total += A480.a - total += A481.a - total += A482.a - total += A483.a - total += A484.a - total += A485.a - total += A486.a - total += A487.a - total += A488.a - total += A489.a - total += A490.a - total += A491.a - total += A492.a - total += A493.a - total += A494.a - total += A495.a - total += A496.a - total += A497.a - total += A498.a - total += A499.a - }.toDouble() / 500 + total += A0.a + total += A1.a + total += A2.a + total += A3.a + total += A4.a + total += A5.a + total += A6.a + total += A7.a + total += A8.a + total += A9.a + total += A10.a + total += A11.a + total += A12.a + total += A13.a + total += A14.a + total += A15.a + total += A16.a + total += A17.a + total += A18.a + total += A19.a + total += A20.a + total += A21.a + total += A22.a + total += A23.a + total += A24.a + total += A25.a + total += A26.a + total += A27.a + total += A28.a + total += A29.a + total += A30.a + total += A31.a + total += A32.a + total += A33.a + total += A34.a + total += A35.a + total += A36.a + total += A37.a + total += A38.a + total += A39.a + total += A40.a + total += A41.a + total += A42.a + total += A43.a + total += A44.a + total += A45.a + total += A46.a + total += A47.a + total += A48.a + total += A49.a + total += A50.a + total += A51.a + total += A52.a + total += A53.a + total += A54.a + total += A55.a + total += A56.a + total += A57.a + total += A58.a + total += A59.a + total += A60.a + total += A61.a + total += A62.a + total += A63.a + total += A64.a + total += A65.a + total += A66.a + total += A67.a + total += A68.a + total += A69.a + total += A70.a + total += A71.a + total += A72.a + total += A73.a + total += A74.a + total += A75.a + total += A76.a + total += A77.a + total += A78.a + total += A79.a + total += A80.a + total += A81.a + total += A82.a + total += A83.a + total += A84.a + total += A85.a + total += A86.a + total += A87.a + total += A88.a + total += A89.a + total += A90.a + total += A91.a + total += A92.a + total += A93.a + total += A94.a + total += A95.a + total += A96.a + total += A97.a + total += A98.a + total += A99.a + total += A100.a + total += A101.a + total += A102.a + total += A103.a + total += A104.a + total += A105.a + total += A106.a + total += A107.a + total += A108.a + total += A109.a + total += A110.a + total += A111.a + total += A112.a + total += A113.a + total += A114.a + total += A115.a + total += A116.a + total += A117.a + total += A118.a + total += A119.a + total += A120.a + total += A121.a + total += A122.a + total += A123.a + total += A124.a + total += A125.a + total += A126.a + total += A127.a + total += A128.a + total += A129.a + total += A130.a + total += A131.a + total += A132.a + total += A133.a + total += A134.a + total += A135.a + total += A136.a + total += A137.a + total += A138.a + total += A139.a + total += A140.a + total += A141.a + total += A142.a + total += A143.a + total += A144.a + total += A145.a + total += A146.a + total += A147.a + total += A148.a + total += A149.a + total += A150.a + total += A151.a + total += A152.a + total += A153.a + total += A154.a + total += A155.a + total += A156.a + total += A157.a + total += A158.a + total += A159.a + total += A160.a + total += A161.a + total += A162.a + total += A163.a + total += A164.a + total += A165.a + total += A166.a + total += A167.a + total += A168.a + total += A169.a + total += A170.a + total += A171.a + total += A172.a + total += A173.a + total += A174.a + total += A175.a + total += A176.a + total += A177.a + total += A178.a + total += A179.a + total += A180.a + total += A181.a + total += A182.a + total += A183.a + total += A184.a + total += A185.a + total += A186.a + total += A187.a + total += A188.a + total += A189.a + total += A190.a + total += A191.a + total += A192.a + total += A193.a + total += A194.a + total += A195.a + total += A196.a + total += A197.a + total += A198.a + total += A199.a + total += A200.a + total += A201.a + total += A202.a + total += A203.a + total += A204.a + total += A205.a + total += A206.a + total += A207.a + total += A208.a + total += A209.a + total += A210.a + total += A211.a + total += A212.a + total += A213.a + total += A214.a + total += A215.a + total += A216.a + total += A217.a + total += A218.a + total += A219.a + total += A220.a + total += A221.a + total += A222.a + total += A223.a + total += A224.a + total += A225.a + total += A226.a + total += A227.a + total += A228.a + total += A229.a + total += A230.a + total += A231.a + total += A232.a + total += A233.a + total += A234.a + total += A235.a + total += A236.a + total += A237.a + total += A238.a + total += A239.a + total += A240.a + total += A241.a + total += A242.a + total += A243.a + total += A244.a + total += A245.a + total += A246.a + total += A247.a + total += A248.a + total += A249.a + total += A250.a + total += A251.a + total += A252.a + total += A253.a + total += A254.a + total += A255.a + total += A256.a + total += A257.a + total += A258.a + total += A259.a + total += A260.a + total += A261.a + total += A262.a + total += A263.a + total += A264.a + total += A265.a + total += A266.a + total += A267.a + total += A268.a + total += A269.a + total += A270.a + total += A271.a + total += A272.a + total += A273.a + total += A274.a + total += A275.a + total += A276.a + total += A277.a + total += A278.a + total += A279.a + total += A280.a + total += A281.a + total += A282.a + total += A283.a + total += A284.a + total += A285.a + total += A286.a + total += A287.a + total += A288.a + total += A289.a + total += A290.a + total += A291.a + total += A292.a + total += A293.a + total += A294.a + total += A295.a + total += A296.a + total += A297.a + total += A298.a + total += A299.a + total += A300.a + total += A301.a + total += A302.a + total += A303.a + total += A304.a + total += A305.a + total += A306.a + total += A307.a + total += A308.a + total += A309.a + total += A310.a + total += A311.a + total += A312.a + total += A313.a + total += A314.a + total += A315.a + total += A316.a + total += A317.a + total += A318.a + total += A319.a + total += A320.a + total += A321.a + total += A322.a + total += A323.a + total += A324.a + total += A325.a + total += A326.a + total += A327.a + total += A328.a + total += A329.a + total += A330.a + total += A331.a + total += A332.a + total += A333.a + total += A334.a + total += A335.a + total += A336.a + total += A337.a + total += A338.a + total += A339.a + total += A340.a + total += A341.a + total += A342.a + total += A343.a + total += A344.a + total += A345.a + total += A346.a + total += A347.a + total += A348.a + total += A349.a + total += A350.a + total += A351.a + total += A352.a + total += A353.a + total += A354.a + total += A355.a + total += A356.a + total += A357.a + total += A358.a + total += A359.a + total += A360.a + total += A361.a + total += A362.a + total += A363.a + total += A364.a + total += A365.a + total += A366.a + total += A367.a + total += A368.a + total += A369.a + total += A370.a + total += A371.a + total += A372.a + total += A373.a + total += A374.a + total += A375.a + total += A376.a + total += A377.a + total += A378.a + total += A379.a + total += A380.a + total += A381.a + total += A382.a + total += A383.a + total += A384.a + total += A385.a + total += A386.a + total += A387.a + total += A388.a + total += A389.a + total += A390.a + total += A391.a + total += A392.a + total += A393.a + total += A394.a + total += A395.a + total += A396.a + total += A397.a + total += A398.a + total += A399.a + total += A400.a + total += A401.a + total += A402.a + total += A403.a + total += A404.a + total += A405.a + total += A406.a + total += A407.a + total += A408.a + total += A409.a + total += A410.a + total += A411.a + total += A412.a + total += A413.a + total += A414.a + total += A415.a + total += A416.a + total += A417.a + total += A418.a + total += A419.a + total += A420.a + total += A421.a + total += A422.a + total += A423.a + total += A424.a + total += A425.a + total += A426.a + total += A427.a + total += A428.a + total += A429.a + total += A430.a + total += A431.a + total += A432.a + total += A433.a + total += A434.a + total += A435.a + total += A436.a + total += A437.a + total += A438.a + total += A439.a + total += A440.a + total += A441.a + total += A442.a + total += A443.a + total += A444.a + total += A445.a + total += A446.a + total += A447.a + total += A448.a + total += A449.a + total += A450.a + total += A451.a + total += A452.a + total += A453.a + total += A454.a + total += A455.a + total += A456.a + total += A457.a + total += A458.a + total += A459.a + total += A460.a + total += A461.a + total += A462.a + total += A463.a + total += A464.a + total += A465.a + total += A466.a + total += A467.a + total += A468.a + total += A469.a + total += A470.a + total += A471.a + total += A472.a + total += A473.a + total += A474.a + total += A475.a + total += A476.a + total += A477.a + total += A478.a + total += A479.a + total += A480.a + total += A481.a + total += A482.a + total += A483.a + total += A484.a + total += A485.a + total += A486.a + total += A487.a + total += A488.a + total += A489.a + total += A490.a + total += A491.a + total += A492.a + total += A493.a + total += A494.a + total += A495.a + total += A496.a + total += A497.a + total += A498.a + total += A499.a - return BenchmarkManualResult(BenchmarkResult.Status.PASSED, total, 0, listOf(time)) + return total } private object B0 { val a = Random.nextInt(100) } @@ -1529,16 +1527,13 @@ private object B499 { val a = B498.a + Random.nextInt(100) } private var singletonInitializeNestedRun = false // Benchmark -fun singletonInitializeNested(): BenchmarkManualResult { +fun singletonInitializeNested(): Int { if (singletonInitializeNestedRun) { - return BenchmarkManualResult(BenchmarkResult.Status.FAILED, 0, 0, listOf(0.0)) + error("Function singletonInitializeNested can be called only once.") } singletonInitializeNestedRun = true - var total = 0 - val time = measureNanoTime { - total = B499.a - }.toDouble() / 500 + var total = B499.a - return BenchmarkManualResult(BenchmarkResult.Status.PASSED, total, 0, listOf(time)) + return total } diff --git a/performance/startup/src/main/kotlin/org/jetbrains/startup/Utils.kt b/performance/startup/src/main/kotlin/org/jetbrains/startup/Utils.kt deleted file mode 100644 index 3569bea49b7..00000000000 --- a/performance/startup/src/main/kotlin/org/jetbrains/startup/Utils.kt +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright 2010-2020 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. - */ - -package org.jetbrains.startup - -expect class Random() { - companion object { - var seedInt: Int - fun nextInt(boundary: Int = 100): Int - } -}