Initial import of benchmarks from https://github.com/dzharkov/kotlin-compiler-benchmarks
This commit is contained in:
committed by
Denis Zharkov
parent
1bd5b68b4a
commit
7968ecef1c
@@ -0,0 +1,83 @@
|
|||||||
|
import kotlinx.benchmark.gradle.benchmark
|
||||||
|
|
||||||
|
val benchmarks_version = "0.2.0-dev-4"
|
||||||
|
buildscript {
|
||||||
|
val benchmarks_version = "0.2.0-dev-4"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() == true
|
||||||
|
if (cacheRedirectorEnabled) {
|
||||||
|
maven("https://cache-redirector.jetbrains.com/dl.bintray.com/kotlin/kotlinx")
|
||||||
|
maven("https://cache-redirector.jetbrains.com/dl.bintray.com/kotlin/kotlin-dev")
|
||||||
|
} else {
|
||||||
|
maven("https://dl.bintray.com/kotlin/kotlinx")
|
||||||
|
maven("https://dl.bintray.com/kotlin/kotlin-dev")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath("org.jetbrains.kotlinx:kotlinx.benchmark.gradle:$benchmarks_version")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply(plugin = "kotlinx.benchmark")
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
java
|
||||||
|
kotlin("jvm")
|
||||||
|
id("jps-compatible")
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() == true
|
||||||
|
if (cacheRedirectorEnabled) {
|
||||||
|
maven("https://cache-redirector.jetbrains.com/dl.bintray.com/kotlin/kotlinx")
|
||||||
|
maven("https://cache-redirector.jetbrains.com/dl.bintray.com/kotlin/kotlin-dev")
|
||||||
|
} else {
|
||||||
|
maven("https://dl.bintray.com/kotlin/kotlinx")
|
||||||
|
maven("https://dl.bintray.com/kotlin/kotlin-dev")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile(kotlinStdlib())
|
||||||
|
compile(project(":compiler:frontend"))
|
||||||
|
compile(project(":compiler:cli"))
|
||||||
|
compile(intellijCoreDep()) { includeJars("intellij-core") }
|
||||||
|
compile(jpsStandalone()) { includeJars("jps-model") }
|
||||||
|
Platform[192].orHigher {
|
||||||
|
compile(intellijPluginDep("java"))
|
||||||
|
}
|
||||||
|
compile(intellijDep()) { includeIntellijCoreJarDependencies(project) }
|
||||||
|
compile("org.jetbrains.kotlinx:kotlinx.benchmark.runtime-jvm:$benchmarks_version")
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
"main" { projectDefault() }
|
||||||
|
}
|
||||||
|
|
||||||
|
benchmark {
|
||||||
|
configurations {
|
||||||
|
named("main") {
|
||||||
|
warmups = 10
|
||||||
|
iterations = 10
|
||||||
|
iterationTime = 1
|
||||||
|
iterationTimeUnit = "sec"
|
||||||
|
param("size", 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
register("fir") {
|
||||||
|
warmups = 10
|
||||||
|
iterations = 10
|
||||||
|
iterationTime = 1
|
||||||
|
iterationTimeUnit = "sec"
|
||||||
|
param("isIR", true)
|
||||||
|
param("size", 1000)
|
||||||
|
|
||||||
|
include("CommonCallsBenchmark")
|
||||||
|
//include("InferenceBaselineCallsBenchmark")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
targets {
|
||||||
|
register("main")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.benchmarks
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.Param
|
||||||
|
import org.openjdk.jmh.annotations.Scope
|
||||||
|
import org.openjdk.jmh.annotations.State
|
||||||
|
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
abstract class AbstractInferenceBenchmark : AbstractSimpleFileBenchmark() {
|
||||||
|
@Param("true", "false")
|
||||||
|
private var useNI: Boolean = false
|
||||||
|
|
||||||
|
override val useNewInference: Boolean
|
||||||
|
get() = useNI
|
||||||
|
}
|
||||||
@@ -0,0 +1,213 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.kotlin.benchmarks
|
||||||
|
|
||||||
|
import com.intellij.openapi.Disposable
|
||||||
|
import com.intellij.openapi.extensions.Extensions
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.vfs.CharsetToolkit
|
||||||
|
import com.intellij.psi.PsiElementFinder
|
||||||
|
import com.intellij.psi.PsiFileFactory
|
||||||
|
import com.intellij.psi.impl.PsiFileFactoryImpl
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
|
import com.intellij.testFramework.LightVirtualFile
|
||||||
|
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
||||||
|
import org.jetbrains.kotlin.asJava.finder.JavaElementFinder
|
||||||
|
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltIns
|
||||||
|
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||||
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||||
|
import org.jetbrains.kotlin.cli.jvm.compiler.*
|
||||||
|
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot
|
||||||
|
import org.jetbrains.kotlin.config.*
|
||||||
|
import org.jetbrains.kotlin.context.SimpleGlobalContext
|
||||||
|
import org.jetbrains.kotlin.context.withModule
|
||||||
|
import org.jetbrains.kotlin.context.withProject
|
||||||
|
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||||
|
import org.jetbrains.kotlin.diagnostics.Severity
|
||||||
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
|
import org.jetbrains.kotlin.fir.builder.RawFirBuilder
|
||||||
|
import org.jetbrains.kotlin.fir.java.FirJavaModuleBasedSession
|
||||||
|
import org.jetbrains.kotlin.fir.java.FirLibrarySession
|
||||||
|
import org.jetbrains.kotlin.fir.java.FirProjectSessionProvider
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.FirProvider
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.impl.FirProviderImpl
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.transformers.FirTotalResolveTransformer
|
||||||
|
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||||
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||||
|
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||||
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
|
import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices
|
||||||
|
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices
|
||||||
|
import org.jetbrains.kotlin.storage.ExceptionTracker
|
||||||
|
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||||
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
|
import org.openjdk.jmh.annotations.*
|
||||||
|
import org.openjdk.jmh.infra.Blackhole
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
private fun createFile(shortName: String, text: String, project: Project): KtFile {
|
||||||
|
val virtualFile = object : LightVirtualFile(shortName, KotlinLanguage.INSTANCE, text) {
|
||||||
|
override fun getPath(): String {
|
||||||
|
//TODO: patch LightVirtualFile
|
||||||
|
return "/" + name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtualFile.charset = CharsetToolkit.UTF8_CHARSET
|
||||||
|
val factory = PsiFileFactory.getInstance(project) as PsiFileFactoryImpl
|
||||||
|
|
||||||
|
return factory.trySetupPsiForFile(virtualFile, KotlinLanguage.INSTANCE, true, false) as KtFile
|
||||||
|
}
|
||||||
|
|
||||||
|
private val JDK_PATH = File("${System.getProperty("java.home")!!}/lib/rt.jar")
|
||||||
|
private val RUNTIME_JAR = File(System.getProperty("kotlin.runtime.path") ?: "dist/kotlinc/lib/kotlin-runtime.jar")
|
||||||
|
|
||||||
|
private val LANGUAGE_FEATURE_SETTINGS =
|
||||||
|
LanguageVersionSettingsImpl(
|
||||||
|
LanguageVersion.KOTLIN_1_3, ApiVersion.KOTLIN_1_3,
|
||||||
|
specificFeatures = mapOf(LanguageFeature.NewInference to LanguageFeature.State.ENABLED)
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun newConfiguration(useNewInference: Boolean): CompilerConfiguration {
|
||||||
|
val configuration = CompilerConfiguration()
|
||||||
|
configuration.put(CommonConfigurationKeys.MODULE_NAME, "benchmark")
|
||||||
|
configuration.put(CLIConfigurationKeys.INTELLIJ_PLUGIN_ROOT, "../idea/resources")
|
||||||
|
configuration.addJvmClasspathRoot(JDK_PATH)
|
||||||
|
configuration.addJvmClasspathRoot(RUNTIME_JAR)
|
||||||
|
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
|
||||||
|
|
||||||
|
val newInferenceState = if (useNewInference) LanguageFeature.State.ENABLED else LanguageFeature.State.DISABLED
|
||||||
|
configuration.languageVersionSettings = LanguageVersionSettingsImpl(
|
||||||
|
LanguageVersion.KOTLIN_1_3, ApiVersion.KOTLIN_1_3,
|
||||||
|
specificFeatures = mapOf(
|
||||||
|
LanguageFeature.NewInference to newInferenceState
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return configuration
|
||||||
|
}
|
||||||
|
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
abstract class AbstractSimpleFileBenchmark {
|
||||||
|
|
||||||
|
private var myDisposable: Disposable = Disposable { }
|
||||||
|
private lateinit var env: KotlinCoreEnvironment
|
||||||
|
private lateinit var file: KtFile
|
||||||
|
|
||||||
|
@Param("true", "false")
|
||||||
|
protected var isIR: Boolean = false
|
||||||
|
|
||||||
|
protected open val useNewInference get() = isIR
|
||||||
|
|
||||||
|
@Setup(Level.Trial)
|
||||||
|
fun setUp() {
|
||||||
|
if (isIR && !useNewInference) error("Invalid configuration")
|
||||||
|
env = KotlinCoreEnvironment.createForTests(
|
||||||
|
myDisposable,
|
||||||
|
newConfiguration(useNewInference),
|
||||||
|
EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||||
|
)
|
||||||
|
|
||||||
|
if (isIR) {
|
||||||
|
Extensions.getArea(env.project)
|
||||||
|
.getExtensionPoint(PsiElementFinder.EP_NAME)
|
||||||
|
.unregisterExtension(JavaElementFinder::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
file = createFile(
|
||||||
|
"test.kt",
|
||||||
|
buildText(),
|
||||||
|
env.project
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun analyzeGreenFile(bh: Blackhole) {
|
||||||
|
if (isIR) {
|
||||||
|
analyzeGreenFileIr(bh)
|
||||||
|
} else {
|
||||||
|
analyzeGreenFileFrontend(bh)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun analyzeGreenFileFrontend(bh: Blackhole) {
|
||||||
|
val tracker = ExceptionTracker()
|
||||||
|
val storageManager: StorageManager =
|
||||||
|
LockBasedStorageManager.createWithExceptionHandling("benchmarks", tracker)
|
||||||
|
|
||||||
|
val context = SimpleGlobalContext(storageManager, tracker)
|
||||||
|
val module =
|
||||||
|
ModuleDescriptorImpl(
|
||||||
|
Name.special("<benchmark>"), storageManager,
|
||||||
|
JvmBuiltIns(storageManager, JvmBuiltIns.Kind.FROM_DEPENDENCIES)
|
||||||
|
)
|
||||||
|
val moduleContext = context.withProject(env.project).withModule(module)
|
||||||
|
|
||||||
|
val result = TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||||
|
moduleContext.project,
|
||||||
|
listOf(file),
|
||||||
|
NoScopeRecordCliBindingTrace(),
|
||||||
|
env.configuration,
|
||||||
|
{ scope -> JvmPackagePartProvider(LANGUAGE_FEATURE_SETTINGS, scope) }
|
||||||
|
)
|
||||||
|
|
||||||
|
assert(result.bindingContext.diagnostics.none { it.severity == Severity.ERROR })
|
||||||
|
|
||||||
|
bh.consume(result.shouldGenerateCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun analyzeGreenFileIr(bh: Blackhole) {
|
||||||
|
val scope = GlobalSearchScope.filesScope(env.project, listOf(file.virtualFile))
|
||||||
|
.uniteWith(TopDownAnalyzerFacadeForJVM.AllJavaSourcesInProjectScope(env.project))
|
||||||
|
val session = createSession(env, scope)
|
||||||
|
val builder = RawFirBuilder(session, stubMode = false)
|
||||||
|
|
||||||
|
val totalTransformer = FirTotalResolveTransformer()
|
||||||
|
val firFile = builder.buildFirFile(file).also((session.getService(FirProvider::class) as FirProviderImpl)::recordFile)
|
||||||
|
|
||||||
|
for (transformer in totalTransformer.transformers) {
|
||||||
|
transformer.transformFile(firFile, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
bh.consume(firFile.hashCode())
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract fun buildText(): String
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createSession(
|
||||||
|
environment: KotlinCoreEnvironment,
|
||||||
|
sourceScope: GlobalSearchScope,
|
||||||
|
librariesScope: GlobalSearchScope = GlobalSearchScope.notScope(sourceScope)
|
||||||
|
): FirSession {
|
||||||
|
val moduleInfo = FirTestModuleInfo()
|
||||||
|
val project = environment.project
|
||||||
|
val provider = FirProjectSessionProvider(project)
|
||||||
|
return FirJavaModuleBasedSession(moduleInfo, provider, sourceScope).also {
|
||||||
|
createSessionForDependencies(provider, moduleInfo, librariesScope, environment)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createSessionForDependencies(
|
||||||
|
provider: FirProjectSessionProvider,
|
||||||
|
moduleInfo: FirTestModuleInfo,
|
||||||
|
librariesScope: GlobalSearchScope,
|
||||||
|
environment: KotlinCoreEnvironment
|
||||||
|
) {
|
||||||
|
val dependenciesInfo = FirTestModuleInfo()
|
||||||
|
moduleInfo.dependencies.add(dependenciesInfo)
|
||||||
|
FirLibrarySession.create(
|
||||||
|
dependenciesInfo, provider, librariesScope, environment.project,
|
||||||
|
environment.createPackagePartProvider(librariesScope)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
class FirTestModuleInfo(
|
||||||
|
override val name: Name = Name.identifier("TestModule"),
|
||||||
|
val dependencies: MutableList<ModuleInfo> = mutableListOf(),
|
||||||
|
override val platform: TargetPlatform = JvmPlatforms.unspecifiedJvmPlatform,
|
||||||
|
override val analyzerServices: PlatformDependentAnalyzerServices = JvmPlatformAnalyzerServices
|
||||||
|
) : ModuleInfo {
|
||||||
|
override fun dependencies(): List<ModuleInfo> = dependencies
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.benchmarks
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.*
|
||||||
|
import org.openjdk.jmh.infra.Blackhole
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
open class CommonCallsBenchmark : AbstractSimpleFileBenchmark(){
|
||||||
|
|
||||||
|
@Param("1", "10", "100", "1000", "3000", "5000", "7000", "10000")
|
||||||
|
private var size: Int = 0
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
fun benchmark(bh: Blackhole) {
|
||||||
|
analyzeGreenFile(bh)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun buildText() =
|
||||||
|
"""
|
||||||
|
|fun foo(): Int = 1
|
||||||
|
|
|
||||||
|
|fun bar() {
|
||||||
|
|${(1..size).joinToString("\n") { " foo()" }}
|
||||||
|
|}
|
||||||
|
""".trimMargin()
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.benchmarks
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.*
|
||||||
|
import org.openjdk.jmh.infra.Blackhole
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
open class ComplexDataFlowBenchmark : AbstractSimpleFileBenchmark(){
|
||||||
|
|
||||||
|
@Param("1", "100", "1000", "3000", "5000", "7000", "10000")
|
||||||
|
private var size: Int = 0
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
fun benchmark(bh: Blackhole) {
|
||||||
|
analyzeGreenFile(bh)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun buildText() =
|
||||||
|
"""
|
||||||
|
|
|
||||||
|
|fun bar(x: Any?) {
|
||||||
|
| var y = x
|
||||||
|
|${(1..size).joinToString("\n") {
|
||||||
|
"""
|
||||||
|
|if (x is String) {
|
||||||
|
| y = x
|
||||||
|
|}
|
||||||
|
|y = 1
|
||||||
|
""".trimMargin()
|
||||||
|
}}
|
||||||
|
|}
|
||||||
|
""".trimMargin()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.kotlin.benchmarks
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.*
|
||||||
|
import org.openjdk.jmh.infra.Blackhole
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
open class ControlFlowOperators : AbstractSimpleFileBenchmark(){
|
||||||
|
|
||||||
|
@Param("1", "100", "1000", "3000", "5000", "7000", "10000")
|
||||||
|
private var size: Int = 0
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
fun benchmark(bh: Blackhole) {
|
||||||
|
analyzeGreenFile(bh)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun buildText() =
|
||||||
|
"""
|
||||||
|
|var isTrue = true
|
||||||
|
|var s = ""
|
||||||
|
|fun bar() {
|
||||||
|
|${(1..size).joinToString("\n") {
|
||||||
|
"""
|
||||||
|
|var x$it: String
|
||||||
|
|
|
||||||
|
|when (s) {
|
||||||
|
| "A" -> { x$it = "1" }
|
||||||
|
| "B" -> { x$it = "2" }
|
||||||
|
| else -> { x$it = "3" }
|
||||||
|
|}
|
||||||
|
|
|
||||||
|
|while (isTrue) {
|
||||||
|
| x$it.hashCode()
|
||||||
|
|}
|
||||||
|
""".trimMargin()
|
||||||
|
}}
|
||||||
|
|}
|
||||||
|
""".trimMargin()
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.benchmarks
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.*
|
||||||
|
import org.openjdk.jmh.infra.Blackhole
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
open class InferenceBaselineCallsBenchmark : AbstractSimpleFileBenchmark() {
|
||||||
|
|
||||||
|
@Param("1", "10", "100", "1000", "5000", "10000")
|
||||||
|
private var size: Int = 0
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
fun benchmark(bh: Blackhole) {
|
||||||
|
analyzeGreenFile(bh)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun buildText() =
|
||||||
|
"""
|
||||||
|
|fun foo(x: Int): Int = 1
|
||||||
|
|fun expectsInt(x: Int) {}
|
||||||
|
|fun bar(v: Int) {
|
||||||
|
|${(1..size).map { " expectsInt(foo(v))" }.joinToString("\n")}
|
||||||
|
|}
|
||||||
|
""".trimMargin()
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.benchmarks
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.*
|
||||||
|
import org.openjdk.jmh.infra.Blackhole
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
open class InferenceExplicitArgumentsCallsBenchmark : AbstractInferenceBenchmark() {
|
||||||
|
|
||||||
|
@Param("1", "10", "100", "1000", "5000", "10000")
|
||||||
|
private var size: Int = 0
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
fun benchmark(bh: Blackhole) {
|
||||||
|
analyzeGreenFile(bh)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun buildText() =
|
||||||
|
"""
|
||||||
|
|fun <T> foo(x: T): Int = 1
|
||||||
|
|fun expectsInt(x: Int) {}
|
||||||
|
|fun bar(v: Int) {
|
||||||
|
|${(1..size).map { " expectsInt(foo<Int>(v))" }.joinToString("\n")}
|
||||||
|
|}
|
||||||
|
""".trimMargin()
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.benchmarks
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.*
|
||||||
|
import org.openjdk.jmh.infra.Blackhole
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
open class InferenceForInApplicableCandidate : AbstractInferenceBenchmark() {
|
||||||
|
|
||||||
|
@Param("1", "10", "100", "1000", "5000", "10000")
|
||||||
|
private var size: Int = 1
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
fun benchmark(bh: Blackhole) {
|
||||||
|
analyzeGreenFile(bh)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun buildText() =
|
||||||
|
"""
|
||||||
|
|fun <T : Comparable<T>> foo(x: MutableList<T>) {}
|
||||||
|
|fun <T> foo(x: MutableList<T>, y: (T, T) -> Int) {}
|
||||||
|
|fun bar(x: MutableList<Any>) {
|
||||||
|
|${(1..size).joinToString("\n") { " foo(x) { a, b -> 1 }" }}
|
||||||
|
|}
|
||||||
|
""".trimMargin()
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.benchmarks
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.*
|
||||||
|
import org.openjdk.jmh.infra.Blackhole
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
open class InferenceFromArgumentCallsBenchmark : AbstractInferenceBenchmark() {
|
||||||
|
|
||||||
|
@Param("1", "10", "100", "1000", "5000", "10000")
|
||||||
|
private var size: Int = 0
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
fun benchmark(bh: Blackhole) {
|
||||||
|
analyzeGreenFile(bh)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun buildText() =
|
||||||
|
"""
|
||||||
|
|fun <T> foo(x: T): Int = 1
|
||||||
|
|fun expectsInt(x: Int) {}
|
||||||
|
|fun bar(v: Int) {
|
||||||
|
|${(1..size).map { " expectsInt(foo(v))" }.joinToString("\n")}
|
||||||
|
|}
|
||||||
|
""".trimMargin()
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.benchmarks
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.*
|
||||||
|
import org.openjdk.jmh.infra.Blackhole
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
open class InferenceFromReturnTypeCallsBenchmark : AbstractInferenceBenchmark() {
|
||||||
|
|
||||||
|
@Param("1", "10", "100", "1000", "5000", "10000")
|
||||||
|
private var size: Int = 0
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
fun benchmark(bh: Blackhole) {
|
||||||
|
analyzeGreenFile(bh)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun buildText() =
|
||||||
|
"""
|
||||||
|
|fun <T> foo(x: Int): T = null!!
|
||||||
|
|fun expectsInt(x: Int) {}
|
||||||
|
|fun bar(v: Int) {
|
||||||
|
|${(1..size).map { " expectsInt(foo(v))" }.joinToString("\n")}
|
||||||
|
|}
|
||||||
|
""".trimMargin()
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.benchmarks
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.*
|
||||||
|
import org.openjdk.jmh.infra.Blackhole
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
open class IntArrayPlusBenchmark : AbstractSimpleFileBenchmark() {
|
||||||
|
|
||||||
|
@Param("1", "10", "100", "1000", "3000", "5000", "7000", "10000")
|
||||||
|
private var size: Int = 0
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
//@Fork(jvmArgsAppend = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"])
|
||||||
|
fun benchmark(bh: Blackhole) {
|
||||||
|
if (!isIR) error("Doesn't make sense to run it on old frontend on buildserver")
|
||||||
|
analyzeGreenFile(bh)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun buildText() =
|
||||||
|
"""
|
||||||
|
|fun bar(x: IntArray, y: IntArray) {
|
||||||
|
|${(1..size).joinToString("\n") { " x + y" }}
|
||||||
|
|}
|
||||||
|
""".trimMargin()
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.benchmarks
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.*
|
||||||
|
import org.openjdk.jmh.infra.Blackhole
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
open class ManyValsBenchmark : AbstractSimpleFileBenchmark(){
|
||||||
|
|
||||||
|
@Param("1", "100", "1000", "3000", "5000", "7000", "10000")
|
||||||
|
private var size: Int = 0
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
fun benchmark(bh: Blackhole) {
|
||||||
|
analyzeGreenFile(bh)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun buildText() =
|
||||||
|
"""
|
||||||
|
|fun bar() {
|
||||||
|
|${(1..size).joinToString("\n") { " val x$it: Int = 1" }}
|
||||||
|
|}
|
||||||
|
""".trimMargin()
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.benchmarks
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.*
|
||||||
|
import org.openjdk.jmh.infra.Blackhole
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
open class ManyVarsBenchmark : AbstractSimpleFileBenchmark(){
|
||||||
|
|
||||||
|
@Param("1", "100", "1000", "3000", "5000", "7000", "10000")
|
||||||
|
private var size: Int = 0
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
fun benchmark(bh: Blackhole) {
|
||||||
|
analyzeGreenFile(bh)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun buildText() =
|
||||||
|
"""
|
||||||
|
|fun bar() {
|
||||||
|
|${(1..size).joinToString("\n") { " var x$it: Int = 1" }}
|
||||||
|
|}
|
||||||
|
""".trimMargin()
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.benchmarks
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.*
|
||||||
|
import org.openjdk.jmh.infra.Blackhole
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
open class SimpleDataFlowBenchmark : AbstractSimpleFileBenchmark(){
|
||||||
|
|
||||||
|
@Param("1", "100", "1000", "3000", "5000", "7000", "10000")
|
||||||
|
private var size: Int = 0
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
fun benchmark(bh: Blackhole) {
|
||||||
|
analyzeGreenFile(bh)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun buildText() =
|
||||||
|
"""
|
||||||
|
|fun foo(x: Int): Int = 1
|
||||||
|
|var x = 1
|
||||||
|
|fun bar(v: Int) {
|
||||||
|
|${(1..size).joinToString("\n") { " x = foo(v)" }}
|
||||||
|
|}
|
||||||
|
""".trimMargin()
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ pluginManagement {
|
|||||||
|
|
||||||
// modules
|
// modules
|
||||||
include ":kotlin-build-common",
|
include ":kotlin-build-common",
|
||||||
|
":benchmarks",
|
||||||
":compiler",
|
":compiler",
|
||||||
":compiler:util",
|
":compiler:util",
|
||||||
":kotlin-util-io",
|
":kotlin-util-io",
|
||||||
|
|||||||
Reference in New Issue
Block a user