diff --git a/benchmarks/build.gradle.kts b/benchmarks/build.gradle.kts new file mode 100644 index 00000000000..75accc53830 --- /dev/null +++ b/benchmarks/build.gradle.kts @@ -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") + } +} diff --git a/benchmarks/src/org/jetbrains/kotlin/benchmarks/AbstractInferenceBenchmark.kt b/benchmarks/src/org/jetbrains/kotlin/benchmarks/AbstractInferenceBenchmark.kt new file mode 100644 index 00000000000..1a6e2b265d8 --- /dev/null +++ b/benchmarks/src/org/jetbrains/kotlin/benchmarks/AbstractInferenceBenchmark.kt @@ -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 +} \ No newline at end of file diff --git a/benchmarks/src/org/jetbrains/kotlin/benchmarks/AbstractSimpleFileBenchmark.kt b/benchmarks/src/org/jetbrains/kotlin/benchmarks/AbstractSimpleFileBenchmark.kt new file mode 100644 index 00000000000..f39531ebf29 --- /dev/null +++ b/benchmarks/src/org/jetbrains/kotlin/benchmarks/AbstractSimpleFileBenchmark.kt @@ -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(""), 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 = mutableListOf(), + override val platform: TargetPlatform = JvmPlatforms.unspecifiedJvmPlatform, + override val analyzerServices: PlatformDependentAnalyzerServices = JvmPlatformAnalyzerServices +) : ModuleInfo { + override fun dependencies(): List = dependencies +} diff --git a/benchmarks/src/org/jetbrains/kotlin/benchmarks/CommonCallsBenchmark.kt b/benchmarks/src/org/jetbrains/kotlin/benchmarks/CommonCallsBenchmark.kt new file mode 100644 index 00000000000..4c108e0ba79 --- /dev/null +++ b/benchmarks/src/org/jetbrains/kotlin/benchmarks/CommonCallsBenchmark.kt @@ -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() +} \ No newline at end of file diff --git a/benchmarks/src/org/jetbrains/kotlin/benchmarks/ComplexDataFlowBenchmark.kt b/benchmarks/src/org/jetbrains/kotlin/benchmarks/ComplexDataFlowBenchmark.kt new file mode 100644 index 00000000000..00a64f9b650 --- /dev/null +++ b/benchmarks/src/org/jetbrains/kotlin/benchmarks/ComplexDataFlowBenchmark.kt @@ -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() + +} + diff --git a/benchmarks/src/org/jetbrains/kotlin/benchmarks/ControlFlowOperators.kt b/benchmarks/src/org/jetbrains/kotlin/benchmarks/ControlFlowOperators.kt new file mode 100644 index 00000000000..d2b12922ad9 --- /dev/null +++ b/benchmarks/src/org/jetbrains/kotlin/benchmarks/ControlFlowOperators.kt @@ -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() +} diff --git a/benchmarks/src/org/jetbrains/kotlin/benchmarks/InferenceBaselineCallsBenchmark.kt b/benchmarks/src/org/jetbrains/kotlin/benchmarks/InferenceBaselineCallsBenchmark.kt new file mode 100644 index 00000000000..c5c60f9c928 --- /dev/null +++ b/benchmarks/src/org/jetbrains/kotlin/benchmarks/InferenceBaselineCallsBenchmark.kt @@ -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() +} \ No newline at end of file diff --git a/benchmarks/src/org/jetbrains/kotlin/benchmarks/InferenceExplicitArgumentsCallsBenchmark.kt b/benchmarks/src/org/jetbrains/kotlin/benchmarks/InferenceExplicitArgumentsCallsBenchmark.kt new file mode 100644 index 00000000000..472d6e8390c --- /dev/null +++ b/benchmarks/src/org/jetbrains/kotlin/benchmarks/InferenceExplicitArgumentsCallsBenchmark.kt @@ -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 foo(x: T): Int = 1 + |fun expectsInt(x: Int) {} + |fun bar(v: Int) { + |${(1..size).map { " expectsInt(foo(v))" }.joinToString("\n")} + |} + """.trimMargin() +} \ No newline at end of file diff --git a/benchmarks/src/org/jetbrains/kotlin/benchmarks/InferenceForInApplicableCandidate.kt b/benchmarks/src/org/jetbrains/kotlin/benchmarks/InferenceForInApplicableCandidate.kt new file mode 100644 index 00000000000..ec3bdeb5af5 --- /dev/null +++ b/benchmarks/src/org/jetbrains/kotlin/benchmarks/InferenceForInApplicableCandidate.kt @@ -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 > foo(x: MutableList) {} + |fun foo(x: MutableList, y: (T, T) -> Int) {} + |fun bar(x: MutableList) { + |${(1..size).joinToString("\n") { " foo(x) { a, b -> 1 }" }} + |} + """.trimMargin() +} diff --git a/benchmarks/src/org/jetbrains/kotlin/benchmarks/InferenceFromArgumentCallsBenchmark.kt b/benchmarks/src/org/jetbrains/kotlin/benchmarks/InferenceFromArgumentCallsBenchmark.kt new file mode 100644 index 00000000000..02efd0bfbb0 --- /dev/null +++ b/benchmarks/src/org/jetbrains/kotlin/benchmarks/InferenceFromArgumentCallsBenchmark.kt @@ -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 foo(x: T): Int = 1 + |fun expectsInt(x: Int) {} + |fun bar(v: Int) { + |${(1..size).map { " expectsInt(foo(v))" }.joinToString("\n")} + |} + """.trimMargin() +} \ No newline at end of file diff --git a/benchmarks/src/org/jetbrains/kotlin/benchmarks/InferenceFromReturnTypeCallsBenchmark.kt b/benchmarks/src/org/jetbrains/kotlin/benchmarks/InferenceFromReturnTypeCallsBenchmark.kt new file mode 100644 index 00000000000..3b2660a87fd --- /dev/null +++ b/benchmarks/src/org/jetbrains/kotlin/benchmarks/InferenceFromReturnTypeCallsBenchmark.kt @@ -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 foo(x: Int): T = null!! + |fun expectsInt(x: Int) {} + |fun bar(v: Int) { + |${(1..size).map { " expectsInt(foo(v))" }.joinToString("\n")} + |} + """.trimMargin() +} \ No newline at end of file diff --git a/benchmarks/src/org/jetbrains/kotlin/benchmarks/IntArrayPlusBenchmark.kt b/benchmarks/src/org/jetbrains/kotlin/benchmarks/IntArrayPlusBenchmark.kt new file mode 100644 index 00000000000..b969c38f31e --- /dev/null +++ b/benchmarks/src/org/jetbrains/kotlin/benchmarks/IntArrayPlusBenchmark.kt @@ -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() +} \ No newline at end of file diff --git a/benchmarks/src/org/jetbrains/kotlin/benchmarks/ManyValsBenchmark.kt b/benchmarks/src/org/jetbrains/kotlin/benchmarks/ManyValsBenchmark.kt new file mode 100644 index 00000000000..d4f761ad59f --- /dev/null +++ b/benchmarks/src/org/jetbrains/kotlin/benchmarks/ManyValsBenchmark.kt @@ -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() +} \ No newline at end of file diff --git a/benchmarks/src/org/jetbrains/kotlin/benchmarks/ManyVarsBenchmark.kt b/benchmarks/src/org/jetbrains/kotlin/benchmarks/ManyVarsBenchmark.kt new file mode 100644 index 00000000000..eced6a74a68 --- /dev/null +++ b/benchmarks/src/org/jetbrains/kotlin/benchmarks/ManyVarsBenchmark.kt @@ -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() +} \ No newline at end of file diff --git a/benchmarks/src/org/jetbrains/kotlin/benchmarks/SimpleDataFlowBenchmark.kt b/benchmarks/src/org/jetbrains/kotlin/benchmarks/SimpleDataFlowBenchmark.kt new file mode 100644 index 00000000000..37e02297154 --- /dev/null +++ b/benchmarks/src/org/jetbrains/kotlin/benchmarks/SimpleDataFlowBenchmark.kt @@ -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() + + +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 846a8bd0f28..98768c00906 100644 --- a/settings.gradle +++ b/settings.gradle @@ -20,6 +20,7 @@ pluginManagement { // modules include ":kotlin-build-common", + ":benchmarks", ":compiler", ":compiler:util", ":kotlin-util-io",