Move everything under kotlin-native folder

I was forced to manually do update the following files, because otherwise
they would be ignored according .gitignore settings. Probably they
should be deleted from repo.

Interop/.idea/compiler.xml
Interop/.idea/gradle.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml
Interop/.idea/modules.xml
Interop/.idea/modules/Indexer/Indexer.iml
Interop/.idea/modules/Runtime/Runtime.iml
Interop/.idea/modules/StubGenerator/StubGenerator.iml
backend.native/backend.native.iml
backend.native/bc.frontend/bc.frontend.iml
backend.native/cli.bc/cli.bc.iml
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt
backend.native/tests/link/lib/foo.kt
backend.native/tests/link/lib/foo2.kt
backend.native/tests/teamcity-test.property
This commit is contained in:
Stanislav Erokhin
2020-10-27 21:00:28 +03:00
parent 91e4162dad
commit f624800b84
2830 changed files with 0 additions and 0 deletions
@@ -0,0 +1,24 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
plugins {
id("benchmarking")
}
val defaultBuildType = NativeBuildType.RELEASE
benchmark {
applicationName = "Ring"
commonSrcDirs = listOf("../../tools/benchmarks/shared/src/main/kotlin/report", "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")
buildType = (findProperty("nativeBuildType") as String?)?.let { NativeBuildType.valueOf(it) } ?: defaultBuildType
dependencies.common(project(":endorsedLibraries:kotlinx.cli"))
}
@@ -0,0 +1 @@
kotlin.native.home=../../dist
@@ -0,0 +1,5 @@
package org.jetbrains.ring
class konan {
annotation class ThreadLocal
}
@@ -0,0 +1,3 @@
package org.jetbrains.ring
actual fun cleanup() { }
@@ -0,0 +1,101 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater
import java.util.concurrent.locks.ReentrantLock
internal var interceptor: AtomicOperationInterceptor = DefaultInterceptor
private set
private val interceptorLock = ReentrantLock()
internal fun lockAndSetInterceptor(impl: AtomicOperationInterceptor) {
if (!interceptorLock.tryLock() || interceptor !== DefaultInterceptor) {
error("Interceptor is locked by another test: $interceptor")
}
interceptor = impl
}
internal fun unlockAndResetInterceptor(impl: AtomicOperationInterceptor) {
check(interceptor === impl) { "Unexpected interceptor found: $interceptor" }
interceptor = DefaultInterceptor
interceptorLock.unlock()
}
/**
* Interceptor for modifications of atomic variables.
*/
internal open class AtomicOperationInterceptor {
open fun <T> beforeUpdate(ref: AtomicRef<T>) {}
open fun <T> afterSet(ref: AtomicRef<T>, newValue: T) {}
open fun <T> afterRMW(ref: AtomicRef<T>, oldValue: T, newValue: T) {}
}
private object DefaultInterceptor : AtomicOperationInterceptor() {
override fun toString(): String = "DefaultInterceptor"
}
@Suppress("UNCHECKED_CAST")
public actual class AtomicRef<T> internal constructor(value: T) {
/**
* Reading/writing this property maps to read/write of volatile variable.
*/
@Volatile
public actual var value: T = value
set(value) {
interceptor.beforeUpdate(this)
field = value
interceptor.afterSet(this, value)
}
/**
* Maps to [AtomicReferenceFieldUpdater.lazySet].
*/
public actual fun lazySet(value: T) {
interceptor.beforeUpdate(this)
FU.lazySet(this, value)
interceptor.afterSet(this, value)
}
/**
* Maps to [AtomicReferenceFieldUpdater.compareAndSet].
*/
public actual fun compareAndSet(expect: T, update: T): Boolean {
interceptor.beforeUpdate(this)
val result = FU.compareAndSet(this, expect, update)
if (result) interceptor.afterRMW(this, expect, update)
return result
}
/**
* Maps to [AtomicReferenceFieldUpdater.getAndSet].
*/
public actual fun getAndSet(value: T): T {
interceptor.beforeUpdate(this)
val oldValue = FU.getAndSet(this, value) as T
interceptor.afterRMW(this, oldValue, value)
return oldValue
}
override fun toString(): String = value.toString()
private companion object {
private val FU = AtomicReferenceFieldUpdater.newUpdater(AtomicRef::class.java, Any::class.java, "value")
}
}
public actual fun <T> atomic(initial: T): AtomicRef<T> = AtomicRef<T>(initial)
@@ -0,0 +1,5 @@
package org.jetbrains.ring
import kotlin.native.internal.GC
actual fun cleanup() { GC.collect() }
@@ -0,0 +1,53 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
import kotlin.native.concurrent.FreezableAtomicReference as KAtomicRef
import kotlin.native.concurrent.isFrozen
import kotlin.native.concurrent.freeze
public actual class AtomicRef<T> constructor(@PublishedApi internal val a: KAtomicRef<T>) {
public actual inline var value: T
get() = a.value
set(value) {
if (a.isFrozen) value.freeze()
a.value = value
}
public actual inline fun lazySet(value: T) {
if (a.isFrozen) value.freeze()
a.value = value
}
public actual inline fun compareAndSet(expect: T, update: T): Boolean {
if (a.isFrozen) update.freeze()
return a.compareAndSet(expect, update)
}
public actual fun getAndSet(value: T): T {
if (a.isFrozen) value.freeze()
while (true) {
val cur = a.value
if (cur === value) return cur
if (a.compareAndSwap(cur, value) === cur) return cur
}
}
override fun toString(): String = value.toString()
}
public actual fun <T> atomic(initial: T): AtomicRef<T> = AtomicRef<T>(KAtomicRef(initial))
@@ -0,0 +1,3 @@
package org.jetbrains.ring
expect fun cleanup()
@@ -0,0 +1,226 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.jetbrains.ring.*
import octoTest
import org.jetbrains.benchmarksLauncher.*
import kotlinx.cli.*
class RingLauncher : Launcher() {
override val benchmarks = BenchmarksCollection(
mutableMapOf(
"AbstractMethod.sortStrings" to BenchmarkEntryWithInit.create(::AbstractMethodBenchmark, { sortStrings() }),
"AbstractMethod.sortStringsWithComparator" to BenchmarkEntryWithInit.create(::AbstractMethodBenchmark, { sortStringsWithComparator() }),
"AllocationBenchmark.allocateObjects" to BenchmarkEntryWithInit.create(::AllocationBenchmark, { allocateObjects() }),
"ClassArray.copy" to BenchmarkEntryWithInit.create(::ClassArrayBenchmark, { copy() }),
"ClassArray.copyManual" to BenchmarkEntryWithInit.create(::ClassArrayBenchmark, { copyManual() }),
"ClassArray.filterAndCount" to BenchmarkEntryWithInit.create(::ClassArrayBenchmark, { filterAndCount() }),
"ClassArray.filterAndMap" to BenchmarkEntryWithInit.create(::ClassArrayBenchmark, { filterAndMap() }),
"ClassArray.filterAndMapManual" to BenchmarkEntryWithInit.create(::ClassArrayBenchmark, { filterAndMapManual() }),
"ClassArray.filter" to BenchmarkEntryWithInit.create(::ClassArrayBenchmark, { filter() }),
"ClassArray.filterManual" to BenchmarkEntryWithInit.create(::ClassArrayBenchmark, { filterManual() }),
"ClassArray.countFilteredManual" to BenchmarkEntryWithInit.create(::ClassArrayBenchmark, { countFilteredManual() }),
"ClassArray.countFiltered" to BenchmarkEntryWithInit.create(::ClassArrayBenchmark, { countFiltered() }),
"ClassArray.countFilteredLocal" to BenchmarkEntryWithInit.create(::ClassArrayBenchmark, { countFilteredLocal() }),
"ClassBaseline.consume" to BenchmarkEntryWithInit.create(::ClassBaselineBenchmark, { consume() }),
"ClassBaseline.consumeField" to BenchmarkEntryWithInit.create(::ClassBaselineBenchmark, { consumeField() }),
"ClassBaseline.allocateList" to BenchmarkEntryWithInit.create(::ClassBaselineBenchmark, { allocateList() }),
"ClassBaseline.allocateArray" to BenchmarkEntryWithInit.create(::ClassBaselineBenchmark, { allocateArray() }),
"ClassBaseline.allocateListAndFill" to BenchmarkEntryWithInit.create(::ClassBaselineBenchmark, { allocateListAndFill() }),
"ClassBaseline.allocateListAndWrite" to BenchmarkEntryWithInit.create(::ClassBaselineBenchmark, { allocateListAndWrite() }),
"ClassBaseline.allocateArrayAndFill" to BenchmarkEntryWithInit.create(::ClassBaselineBenchmark, { allocateArrayAndFill() }),
"ClassList.copy" to BenchmarkEntryWithInit.create(::ClassListBenchmark, { copy() }),
"ClassList.copyManual" to BenchmarkEntryWithInit.create(::ClassListBenchmark, { copyManual() }),
"ClassList.filterAndCount" to BenchmarkEntryWithInit.create(::ClassListBenchmark, { filterAndCount() }),
"ClassList.filterAndCountWithLambda" to BenchmarkEntryWithInit.create(::ClassListBenchmark, { filterAndCountWithLambda() }),
"ClassList.filterWithLambda" to BenchmarkEntryWithInit.create(::ClassListBenchmark, { filterWithLambda() }),
"ClassList.mapWithLambda" to BenchmarkEntryWithInit.create(::ClassListBenchmark, { mapWithLambda() }),
"ClassList.countWithLambda" to BenchmarkEntryWithInit.create(::ClassListBenchmark, { countWithLambda() }),
"ClassList.filterAndMapWithLambda" to BenchmarkEntryWithInit.create(::ClassListBenchmark, { filterAndMapWithLambda() }),
"ClassList.filterAndMapWithLambdaAsSequence" to BenchmarkEntryWithInit.create(::ClassListBenchmark, { filterAndMapWithLambdaAsSequence() }),
"ClassList.filterAndMap" to BenchmarkEntryWithInit.create(::ClassListBenchmark, { filterAndMap() }),
"ClassList.filterAndMapManual" to BenchmarkEntryWithInit.create(::ClassListBenchmark, { filterAndMapManual() }),
"ClassList.filter" to BenchmarkEntryWithInit.create(::ClassListBenchmark, { filter() }),
"ClassList.filterManual" to BenchmarkEntryWithInit.create(::ClassListBenchmark, { filterManual() }),
"ClassList.countFilteredManual" to BenchmarkEntryWithInit.create(::ClassListBenchmark, { countFilteredManual() }),
"ClassList.countFiltered" to BenchmarkEntryWithInit.create(::ClassListBenchmark, { countFiltered() }),
"ClassList.reduce" to BenchmarkEntryWithInit.create(::ClassListBenchmark, { reduce() }),
"ClassStream.copy" to BenchmarkEntryWithInit.create(::ClassStreamBenchmark, { copy() }),
"ClassStream.copyManual" to BenchmarkEntryWithInit.create(::ClassStreamBenchmark, { copyManual() }),
"ClassStream.filterAndCount" to BenchmarkEntryWithInit.create(::ClassStreamBenchmark, { filterAndCount() }),
"ClassStream.filterAndMap" to BenchmarkEntryWithInit.create(::ClassStreamBenchmark, { filterAndMap() }),
"ClassStream.filterAndMapManual" to BenchmarkEntryWithInit.create(::ClassStreamBenchmark, { filterAndMapManual() }),
"ClassStream.filter" to BenchmarkEntryWithInit.create(::ClassStreamBenchmark, { filter() }),
"ClassStream.filterManual" to BenchmarkEntryWithInit.create(::ClassStreamBenchmark, { filterManual() }),
"ClassStream.countFilteredManual" to BenchmarkEntryWithInit.create(::ClassStreamBenchmark, { countFilteredManual() }),
"ClassStream.countFiltered" to BenchmarkEntryWithInit.create(::ClassStreamBenchmark, { countFiltered() }),
"ClassStream.reduce" to BenchmarkEntryWithInit.create(::ClassStreamBenchmark, { reduce() }),
"CompanionObject.invokeRegularFunction" to BenchmarkEntryWithInit.create(::CompanionObjectBenchmark, { invokeRegularFunction() }),
"DefaultArgument.testOneOfTwo" to BenchmarkEntryWithInit.create(::DefaultArgumentBenchmark, { testOneOfTwo() }),
"DefaultArgument.testTwoOfTwo" to BenchmarkEntryWithInit.create(::DefaultArgumentBenchmark, { testTwoOfTwo() }),
"DefaultArgument.testOneOfFour" to BenchmarkEntryWithInit.create(::DefaultArgumentBenchmark, { testOneOfFour() }),
"DefaultArgument.testFourOfFour" to BenchmarkEntryWithInit.create(::DefaultArgumentBenchmark, { testFourOfFour() }),
"DefaultArgument.testOneOfEight" to BenchmarkEntryWithInit.create(::DefaultArgumentBenchmark, { testOneOfEight() }),
"DefaultArgument.testEightOfEight" to BenchmarkEntryWithInit.create(::DefaultArgumentBenchmark, { testEightOfEight() }),
"Elvis.testElvis" to BenchmarkEntryWithInit.create(::ElvisBenchmark, { testElvis() }),
"Elvis.testCompositeElvis" to BenchmarkEntryWithInit.create(::ElvisBenchmark, { testCompositeElvis() }),
"Euler.problem1bySequence" to BenchmarkEntryWithInit.create(::EulerBenchmark, { problem1bySequence() }),
"Euler.problem1" to BenchmarkEntryWithInit.create(::EulerBenchmark, { problem1() }),
"Euler.problem2" to BenchmarkEntryWithInit.create(::EulerBenchmark, { problem2() }),
"Euler.problem4" to BenchmarkEntryWithInit.create(::EulerBenchmark, { problem4() }),
"Euler.problem8" to BenchmarkEntryWithInit.create(::EulerBenchmark, { problem8() }),
"Euler.problem9" to BenchmarkEntryWithInit.create(::EulerBenchmark, { problem9() }),
"Euler.problem14" to BenchmarkEntryWithInit.create(::EulerBenchmark, { problem14() }),
"Euler.problem14full" to BenchmarkEntryWithInit.create(::EulerBenchmark, { problem14full() }),
"Fibonacci.calcClassic" to BenchmarkEntryWithInit.create(::FibonacciBenchmark, { calcClassic() }),
"Fibonacci.calc" to BenchmarkEntryWithInit.create(::FibonacciBenchmark, { calc() }),
"Fibonacci.calcWithProgression" to BenchmarkEntryWithInit.create(::FibonacciBenchmark, { calcWithProgression() }),
"Fibonacci.calcSquare" to BenchmarkEntryWithInit.create(::FibonacciBenchmark, { calcSquare() }),
"ForLoops.arrayLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { arrayLoop() }),
"ForLoops.intArrayLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { intArrayLoop() }),
"ForLoops.floatArrayLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { floatArrayLoop() }),
"ForLoops.charArrayLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { charArrayLoop() }),
"ForLoops.stringLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { stringLoop() }),
"ForLoops.arrayIndicesLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { arrayIndicesLoop() }),
"ForLoops.intArrayIndicesLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { intArrayIndicesLoop() }),
"ForLoops.floatArrayIndicesLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { floatArrayIndicesLoop() }),
"ForLoops.charArrayIndicesLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { charArrayIndicesLoop() }),
"ForLoops.stringIndicesLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { stringIndicesLoop() }),
"Inline.calculate" to BenchmarkEntryWithInit.create(::InlineBenchmark, { calculate() }),
"Inline.calculateInline" to BenchmarkEntryWithInit.create(::InlineBenchmark, { calculateInline() }),
"Inline.calculateGeneric" to BenchmarkEntryWithInit.create(::InlineBenchmark, { calculateGeneric() }),
"Inline.calculateGenericInline" to BenchmarkEntryWithInit.create(::InlineBenchmark, { calculateGenericInline() }),
"IntArray.copy" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { copy() }),
"IntArray.copyManual" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { copyManual() }),
"IntArray.filterAndCount" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { filterAndCount() }),
"IntArray.filterSomeAndCount" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { filterSomeAndCount() }),
"IntArray.filterAndMap" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { filterAndMap() }),
"IntArray.filterAndMapManual" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { filterAndMapManual() }),
"IntArray.filter" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { filter() }),
"IntArray.filterSome" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { filterSome() }),
"IntArray.filterPrime" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { filterPrime() }),
"IntArray.filterManual" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { filterManual() }),
"IntArray.filterSomeManual" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { filterSomeManual() }),
"IntArray.countFilteredManual" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { countFilteredManual() }),
"IntArray.countFilteredSomeManual" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { countFilteredSomeManual() }),
"IntArray.countFilteredPrimeManual" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { countFilteredPrimeManual() }),
"IntArray.countFiltered" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { countFiltered() }),
"IntArray.countFilteredSome" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { countFilteredSome() }),
"IntArray.countFilteredPrime" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { countFilteredPrime() }),
"IntArray.countFilteredLocal" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { countFilteredLocal() }),
"IntArray.countFilteredSomeLocal" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { countFilteredSomeLocal() }),
"IntArray.reduce" to BenchmarkEntryWithInit.create(::IntArrayBenchmark, { reduce() }),
"IntBaseline.consume" to BenchmarkEntryWithInit.create(::IntBaselineBenchmark, { consume() }),
"IntBaseline.allocateList" to BenchmarkEntryWithInit.create(::IntBaselineBenchmark, { allocateList() }),
"IntBaseline.allocateArray" to BenchmarkEntryWithInit.create(::IntBaselineBenchmark, { allocateArray() }),
"IntBaseline.allocateListAndFill" to BenchmarkEntryWithInit.create(::IntBaselineBenchmark, { allocateListAndFill() }),
"IntBaseline.allocateArrayAndFill" to BenchmarkEntryWithInit.create(::IntBaselineBenchmark, { allocateArrayAndFill() }),
"IntList.copy" to BenchmarkEntryWithInit.create(::IntListBenchmark, { copy() }),
"IntList.copyManual" to BenchmarkEntryWithInit.create(::IntListBenchmark, { copyManual() }),
"IntList.filterAndCount" to BenchmarkEntryWithInit.create(::IntListBenchmark, { filterAndCount() }),
"IntList.filterAndMap" to BenchmarkEntryWithInit.create(::IntListBenchmark, { filterAndMap() }),
"IntList.filterAndMapManual" to BenchmarkEntryWithInit.create(::IntListBenchmark, { filterAndMapManual() }),
"IntList.filter" to BenchmarkEntryWithInit.create(::IntListBenchmark, { filter() }),
"IntList.filterManual" to BenchmarkEntryWithInit.create(::IntListBenchmark, { filterManual() }),
"IntList.countFilteredManual" to BenchmarkEntryWithInit.create(::IntListBenchmark, { countFilteredManual() }),
"IntList.countFiltered" to BenchmarkEntryWithInit.create(::IntListBenchmark, { countFiltered() }),
"IntList.countFilteredLocal" to BenchmarkEntryWithInit.create(::IntListBenchmark, { countFilteredLocal() }),
"IntList.reduce" to BenchmarkEntryWithInit.create(::IntListBenchmark, { reduce() }),
"IntStream.copy" to BenchmarkEntryWithInit.create(::IntStreamBenchmark, { copy() }),
"IntStream.copyManual" to BenchmarkEntryWithInit.create(::IntStreamBenchmark, { copyManual() }),
"IntStream.filterAndCount" to BenchmarkEntryWithInit.create(::IntStreamBenchmark, { filterAndCount() }),
"IntStream.filterAndMap" to BenchmarkEntryWithInit.create(::IntStreamBenchmark, { filterAndMap() }),
"IntStream.filterAndMapManual" to BenchmarkEntryWithInit.create(::IntStreamBenchmark, { filterAndMapManual() }),
"IntStream.filter" to BenchmarkEntryWithInit.create(::IntStreamBenchmark, { filter() }),
"IntStream.filterManual" to BenchmarkEntryWithInit.create(::IntStreamBenchmark, { filterManual() }),
"IntStream.countFilteredManual" to BenchmarkEntryWithInit.create(::IntStreamBenchmark, { countFilteredManual() }),
"IntStream.countFiltered" to BenchmarkEntryWithInit.create(::IntStreamBenchmark, { countFiltered() }),
"IntStream.countFilteredLocal" to BenchmarkEntryWithInit.create(::IntStreamBenchmark, { countFilteredLocal() }),
"IntStream.reduce" to BenchmarkEntryWithInit.create(::IntStreamBenchmark, { reduce() }),
"Lambda.noncapturingLambda" to BenchmarkEntryWithInit.create(::LambdaBenchmark, { noncapturingLambda() }),
"Lambda.noncapturingLambdaNoInline" to BenchmarkEntryWithInit.create(::LambdaBenchmark, { noncapturingLambdaNoInline() }),
"Lambda.capturingLambda" to BenchmarkEntryWithInit.create(::LambdaBenchmark, { capturingLambda() }),
"Lambda.capturingLambdaNoInline" to BenchmarkEntryWithInit.create(::LambdaBenchmark, { capturingLambdaNoInline() }),
"Lambda.mutatingLambda" to BenchmarkEntryWithInit.create(::LambdaBenchmark, { mutatingLambda() }),
"Lambda.mutatingLambdaNoInline" to BenchmarkEntryWithInit.create(::LambdaBenchmark, { mutatingLambdaNoInline() }),
"Lambda.methodReference" to BenchmarkEntryWithInit.create(::LambdaBenchmark, { methodReference() }),
"Lambda.methodReferenceNoInline" to BenchmarkEntryWithInit.create(::LambdaBenchmark, { methodReferenceNoInline() }),
"Loop.arrayLoop" to BenchmarkEntryWithInit.create(::LoopBenchmark, { arrayLoop() }),
"Loop.arrayIndexLoop" to BenchmarkEntryWithInit.create(::LoopBenchmark, { arrayIndexLoop() }),
"Loop.rangeLoop" to BenchmarkEntryWithInit.create(::LoopBenchmark, { rangeLoop() }),
"Loop.arrayListLoop" to BenchmarkEntryWithInit.create(::LoopBenchmark, { arrayListLoop() }),
"Loop.arrayWhileLoop" to BenchmarkEntryWithInit.create(::LoopBenchmark, { arrayWhileLoop() }),
"Loop.arrayForeachLoop" to BenchmarkEntryWithInit.create(::LoopBenchmark, { arrayForeachLoop() }),
"Loop.arrayListForeachLoop" to BenchmarkEntryWithInit.create(::LoopBenchmark, { arrayListForeachLoop() }),
"MatrixMap.add" to BenchmarkEntryWithInit.create(::MatrixMapBenchmark, { add() }),
"ParameterNotNull.invokeOneArgWithNullCheck" to BenchmarkEntryWithInit.create(::ParameterNotNullAssertionBenchmark, { invokeOneArgWithNullCheck() }),
"ParameterNotNull.invokeOneArgWithoutNullCheck" to BenchmarkEntryWithInit.create(::ParameterNotNullAssertionBenchmark, { invokeOneArgWithoutNullCheck() }),
"ParameterNotNull.invokeTwoArgsWithNullCheck" to BenchmarkEntryWithInit.create(::ParameterNotNullAssertionBenchmark, { invokeTwoArgsWithNullCheck() }),
"ParameterNotNull.invokeTwoArgsWithoutNullCheck" to BenchmarkEntryWithInit.create(::ParameterNotNullAssertionBenchmark, { invokeTwoArgsWithoutNullCheck() }),
"ParameterNotNull.invokeEightArgsWithNullCheck" to BenchmarkEntryWithInit.create(::ParameterNotNullAssertionBenchmark, { invokeEightArgsWithNullCheck() }),
"ParameterNotNull.invokeEightArgsWithoutNullCheck" to BenchmarkEntryWithInit.create(::ParameterNotNullAssertionBenchmark, { invokeEightArgsWithoutNullCheck() }),
"PrimeList.calcDirect" to BenchmarkEntryWithInit.create(::PrimeListBenchmark, { calcDirect() }),
"PrimeList.calcEratosthenes" to BenchmarkEntryWithInit.create(::PrimeListBenchmark, { calcEratosthenes() }),
"Singleton.access" to BenchmarkEntryWithInit.create(::SingletonBenchmark, { access() }),
"String.stringConcat" to BenchmarkEntryWithInit.create(::StringBenchmark, { stringConcat() }),
"String.stringConcatNullable" to BenchmarkEntryWithInit.create(::StringBenchmark, { stringConcatNullable() }),
"String.stringBuilderConcat" to BenchmarkEntryWithInit.create(::StringBenchmark, { stringBuilderConcat() }),
"String.stringBuilderConcatNullable" to BenchmarkEntryWithInit.create(::StringBenchmark, { stringBuilderConcatNullable() }),
"String.summarizeSplittedCsv" to BenchmarkEntryWithInit.create(::StringBenchmark, { summarizeSplittedCsv() }),
"Switch.testSparseIntSwitch" to BenchmarkEntryWithInit.create(::SwitchBenchmark, { testSparseIntSwitch() }),
"Switch.testDenseIntSwitch" to BenchmarkEntryWithInit.create(::SwitchBenchmark, { testDenseIntSwitch() }),
"Switch.testConstSwitch" to BenchmarkEntryWithInit.create(::SwitchBenchmark, { testConstSwitch() }),
"Switch.testObjConstSwitch" to BenchmarkEntryWithInit.create(::SwitchBenchmark, { testObjConstSwitch() }),
"Switch.testVarSwitch" to BenchmarkEntryWithInit.create(::SwitchBenchmark, { testVarSwitch() }),
"Switch.testStringsSwitch" to BenchmarkEntryWithInit.create(::SwitchBenchmark, { testStringsSwitch() }),
"Switch.testEnumsSwitch" to BenchmarkEntryWithInit.create(::SwitchBenchmark, { testEnumsSwitch() }),
"Switch.testDenseEnumsSwitch" to BenchmarkEntryWithInit.create(::SwitchBenchmark, { testDenseEnumsSwitch() }),
"Switch.testSealedWhenSwitch" to BenchmarkEntryWithInit.create(::SwitchBenchmark, { testSealedWhenSwitch() }),
"WithIndicies.withIndicies" to BenchmarkEntryWithInit.create(::WithIndiciesBenchmark, { withIndicies() }),
"WithIndicies.withIndiciesManual" to BenchmarkEntryWithInit.create(::WithIndiciesBenchmark, { withIndiciesManual() }),
"OctoTest" to BenchmarkEntry(::octoTest),
"Calls.finalMethod" to BenchmarkEntryWithInit.create(::CallsBenchmark, { finalMethodCall() }),
"Calls.openMethodMonomorphic" to BenchmarkEntryWithInit.create(::CallsBenchmark, { classOpenMethodCall_MonomorphicCallsite() }),
"Calls.openMethodBimorphic" to BenchmarkEntryWithInit.create(::CallsBenchmark, { classOpenMethodCall_BimorphicCallsite() }),
"Calls.openMethodTrimorphic" to BenchmarkEntryWithInit.create(::CallsBenchmark, { classOpenMethodCall_TrimorphicCallsite() }),
"Calls.interfaceMethodMonomorphic" to BenchmarkEntryWithInit.create(::CallsBenchmark, { interfaceMethodCall_MonomorphicCallsite() }),
"Calls.interfaceMethodBimorphic" to BenchmarkEntryWithInit.create(::CallsBenchmark, { interfaceMethodCall_BimorphicCallsite() }),
"Calls.interfaceMethodTrimorphic" to BenchmarkEntryWithInit.create(::CallsBenchmark, { interfaceMethodCall_TrimorphicCallsite() }),
"Calls.interfaceMethodHexamorphic" to BenchmarkEntryWithInit.create(::CallsBenchmark, { interfaceMethodCall_HexamorphicCallsite() }),
"Calls.returnBoxUnboxFolding" to BenchmarkEntryWithInit.create(::CallsBenchmark, { returnBoxUnboxFolding() }),
"Calls.parameterBoxUnboxFolding" to BenchmarkEntryWithInit.create(::CallsBenchmark, { parameterBoxUnboxFolding() }),
"CoordinatesSolver.solve" to BenchmarkEntryWithInit.create(::CoordinatesSolverBenchmark, { solve() }),
"GraphSolver.solve" to BenchmarkEntryWithInit.create(::GraphSolverBenchmark, { solve() }),
"Casts.classCast" to BenchmarkEntryWithInit.create(::CastsBenchmark, { classCast() }),
"Casts.interfaceCast" to BenchmarkEntryWithInit.create(::CastsBenchmark, { interfaceCast() }),
"LocalObjects.localArray" to BenchmarkEntryWithInit.create(::LocalObjectsBenchmark, { localArray() }),
"LinkedListWithAtomicsBenchmark" to BenchmarkEntryWithInit.create(::LinkedListWithAtomicsBenchmark, { ensureNext() }),
"Inheritance.baseCalls" to BenchmarkEntryWithInit.create(::InheritanceBenchmark, { baseCalls() })
)
)
}
fun main(args: Array<String>) {
val launcher = RingLauncher()
BenchmarksRunner.runBenchmarks(args, { arguments: BenchmarkArguments ->
if (arguments is BaseBenchmarkArguments) {
launcher.launch(arguments.warmup, arguments.repeat, arguments.prefix,
arguments.filter, arguments.filterRegex, arguments.verbose)
} else emptyList()
}, benchmarksListAction = launcher::benchmarksListAction)
}
@@ -0,0 +1,52 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
/**
* Created by Mikhail.Glukhikh on 06/03/2015.
*
* A benchmark for a single abstract method based on a string comparison
*/
open class AbstractMethodBenchmark {
private val arr: List<String> = zdf_win
private val sequence = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"
private val sequenceMap = HashMap<Char, Int>()
init {
var i = 0;
for (ch in sequence) {
sequenceMap[ch] = i++;
}
}
//Benchmark
fun sortStrings(): Set<String> {
val res = arr.subList(0, if (BENCHMARK_SIZE < arr.size) BENCHMARK_SIZE else arr.size).toSet()
return res
}
//Benchmark
fun sortStringsWithComparator(): Set<String> {
val res = mutableSetOf<String>()
res.addAll(arr.subList(0, if (BENCHMARK_SIZE < arr.size) BENCHMARK_SIZE else arr.size))
return res
}
}
@@ -0,0 +1,25 @@
/*
* 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.ring
var counter = 0
open class AllocationBenchmark {
class MyClass {
fun inc() {
counter++
}
}
//Benchmark
fun allocateObjects() {
repeat(BENCHMARK_SIZE) {
MyClass().inc()
}
}
}
@@ -0,0 +1,301 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
private const val RUNS = 1_000_000
open class CallsBenchmark {
interface I {
fun foo(): Int
fun foo1(): Int = 1
fun foo2(): Int = 2
fun foo3(): Int = 3
fun foo4(): Int = 4
fun foo5(): Int = 5
fun foo6(): Int = 6
fun foo7(): Int = 7
fun foo8(): Int = 8
fun foo9(): Int = 9
fun foo10(): Int = 10
fun foo11(): Int = 11
fun foo12(): Int = 12
fun foo13(): Int = 13
fun foo14(): Int = 14
fun foo15(): Int = 15
fun foo16(): Int = 16
fun foo17(): Int = 17
fun foo18(): Int = 18
fun foo19(): Int = 19
fun foo20(): Int = 20
fun foo21(): Int = 21
fun foo22(): Int = 22
fun foo23(): Int = 23
fun foo24(): Int = 24
fun foo25(): Int = 25
fun foo26(): Int = 26
fun foo27(): Int = 27
fun foo28(): Int = 28
fun foo29(): Int = 29
fun foo30(): Int = 30
fun foo31(): Int = 31
fun foo32(): Int = 32
fun foo33(): Int = 33
fun foo34(): Int = 34
fun foo35(): Int = 35
fun foo36(): Int = 36
fun foo37(): Int = 37
fun foo38(): Int = 38
fun foo39(): Int = 39
fun foo40(): Int = 40
fun foo41(): Int = 41
fun foo42(): Int = 42
fun foo43(): Int = 43
fun foo44(): Int = 44
fun foo45(): Int = 45
fun foo46(): Int = 46
fun foo47(): Int = 47
fun foo48(): Int = 48
fun foo49(): Int = 49
fun foo50(): Int = 50
fun foo51(): Int = 51
fun foo52(): Int = 52
fun foo53(): Int = 53
fun foo54(): Int = 54
fun foo55(): Int = 55
fun foo56(): Int = 56
fun foo57(): Int = 57
fun foo58(): Int = 58
fun foo59(): Int = 59
fun foo60(): Int = 60
fun foo61(): Int = 61
fun foo62(): Int = 62
fun foo63(): Int = 63
fun foo64(): Int = 64
fun foo65(): Int = 65
fun foo66(): Int = 66
fun foo67(): Int = 67
fun foo68(): Int = 68
fun foo69(): Int = 69
fun foo70(): Int = 70
fun foo71(): Int = 71
fun foo72(): Int = 72
fun foo73(): Int = 73
fun foo74(): Int = 74
fun foo75(): Int = 75
fun foo76(): Int = 76
fun foo77(): Int = 77
fun foo78(): Int = 78
fun foo79(): Int = 79
fun foo80(): Int = 80
fun foo81(): Int = 81
fun foo82(): Int = 82
fun foo83(): Int = 83
fun foo84(): Int = 84
fun foo85(): Int = 85
fun foo86(): Int = 86
fun foo87(): Int = 87
fun foo88(): Int = 88
fun foo89(): Int = 89
fun foo90(): Int = 90
fun foo91(): Int = 91
fun foo92(): Int = 92
fun foo93(): Int = 93
fun foo94(): Int = 94
fun foo95(): Int = 95
fun foo96(): Int = 96
fun foo97(): Int = 97
fun foo98(): Int = 98
fun foo99(): Int = 99
}
abstract class A : I
open class B : A() {
override fun foo() = 42
}
open class C : A() {
override fun foo() = 117
}
class D: A() {
override fun foo() = 314
}
open class X : A() {
override fun foo() = 456456
}
open class Y : A() {
override fun foo() = -398473
}
open class Z : A() {
override fun foo() = 78298734
}
val d = D()
val a1: A = B()
val a2: A = C()
val a3: A = d
val i1: I = a1
val i2: I = a2
val i3: I = d
val i4: I = X()
val i5: I = Y()
val i6: I = Z()
fun finalMethodCall(): Int {
var x = 0
// TODO: optimize fields accesses
val d = d
for (i in 0 until RUNS)
x += d.foo()
return x
}
fun classOpenMethodCall_MonomorphicCallsite(): Int {
var x = 0
// TODO: optimize fields accesses
val a1 = a1
for (i in 0 until RUNS)
x += a1.foo()
return x
}
fun classOpenMethodCall_BimorphicCallsite(): Int {
var x = 0
// TODO: optimize fields accesses
val a1 = a1
val a2 = a2
for (i in 0 until RUNS)
x += (if (i and 1 == 0) a1 else a2).foo()
return x
}
fun classOpenMethodCall_TrimorphicCallsite(): Int {
var x = 0
// TODO: optimize fields accesses
val a1 = a1
val a2 = a2
val a3 = a3
for (i in 0 until RUNS)
x += (when (i % 3) {
1 -> a1
2 -> a2
else -> a3
}).foo()
return x
}
fun interfaceMethodCall_MonomorphicCallsite(): Int {
var x = 0
// TODO: optimize fields accesses
val i1 = i1
for (i in 0 until RUNS)
x += i1.foo()
return x
}
fun interfaceMethodCall_BimorphicCallsite(): Int {
var x = 0
// TODO: optimize fields accesses
val i1 = i1
val i2 = i2
for (i in 0 until RUNS)
x += (if (i and 1 == 0) i1 else i2).foo()
return x
}
fun interfaceMethodCall_TrimorphicCallsite(): Int {
var x = 0
// TODO: optimize fields accesses
val i1 = i1
val i2 = i2
val i3 = i3
for (i in 0 until RUNS)
x += (when (i % 3) {
1 -> i1
2 -> i2
else -> i3
}).foo()
return x
}
fun interfaceMethodCall_HexamorphicCallsite(): Int {
var x = 0
// TODO: optimize fields accesses
val i1 = i1
val i2 = i2
val i3 = i3
val i4 = i4
val i5 = i5
val i6 = i6
for (i in 0 until RUNS)
x += (when (i % 6) {
1 -> i1
2 -> i2
3 -> i3
4 -> i4
5 -> i5
else -> i6
}).foo()
return x
}
abstract class E {
abstract fun foo(): Any
}
open class F : E() {
override fun foo(): Int = 42
}
val e: E = F()
fun returnBoxUnboxFolding(): Int {
var x = 0
// TODO: optimize fields accesses
val e = e
for (i in 0 until RUNS)
x += e.foo() as Int
return x
}
abstract class G<in T> {
abstract fun foo(x: T): Int
}
open class H : G<Int>() {
override fun foo(x: Int): Int {
return x
}
}
val g: G<Any> = H() as G<Any>
fun parameterBoxUnboxFolding(): Int {
var x = 0
// TODO: optimize fields accesses
val g = g
for (i in 0 until RUNS)
x += g.foo(i)
return x
}
}
@@ -0,0 +1,117 @@
/*
* Copyright 2010-2018 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.ring
private const val RUNS = 2_000_000
class CastsBenchmark {
interface I0
open class C0: I0
interface I1
open class C1: C0(), I1
interface I2: I0
open class C2: C1(), I2
interface I3: I1
open class C3: C2(), I3
interface I4: I0, I2
open class C4: C3(), I4
interface I5: I3
open class C5: C4(), I5
interface I6: I0, I2, I4
open class C6: C5(), I6
interface I9: I0, I2, I4
open class C9: C5(), I9, I1
interface I7: I1
open class C7: C3(), I7
interface I8: I0, I1
open class C8: C3(), I8
private fun foo_class(c: Any, x: Int, i: Int): Int {
var x = x
if (c is C0) x += i
if (c is C1) x = x xor i
if (c is C2) x += i
if (c is C3) x = x xor i
if (c is C4) x += i
if (c is C5) x = x xor i
if (c is C6) x += i
if (c is C7) x = x xor i
if (c is C8) x += i
if (c is C9) x = x xor i
return x
}
private fun foo_iface(c: Any, x: Int, i: Int): Int {
var x = x
if (c is I0) x += i
if (c is I1) x = x xor i
if (c is I2) x += i
if (c is I3) x = x xor i
if (c is I4) x += i
if (c is I5) x = x xor i
if (c is I6) x += i
if (c is I7) x = x xor i
if (c is I8) x += i
if (c is I9) x = x xor i
return x
}
fun classCast(): Int {
val c0: Any = C0()
val c1: Any = C1()
val c2: Any = C2()
val c3: Any = C3()
val c4: Any = C4()
val c5: Any = C5()
val c6: Any = C6()
val c7: Any = C7()
val c8: Any = C8()
val c9: Any = C9()
var x = 0
for (i in 0 until RUNS) {
x += foo_class(c0, x, i)
x += foo_class(c1, x, i)
x += foo_class(c2, x, i)
x += foo_class(c3, x, i)
x += foo_class(c4, x, i)
x += foo_class(c5, x, i)
x += foo_class(c6, x, i)
x += foo_class(c7, x, i)
x += foo_class(c8, x, i)
x += foo_class(c9, x, i)
}
return x
}
fun interfaceCast(): Int {
val c0: Any = C0()
val c1: Any = C1()
val c2: Any = C2()
val c3: Any = C3()
val c4: Any = C4()
val c5: Any = C5()
val c6: Any = C6()
val c7: Any = C7()
val c8: Any = C8()
val c9: Any = C9()
var x = 0
for (i in 0 until RUNS) {
x += foo_iface(c0, x, i)
x += foo_iface(c1, x, i)
x += foo_iface(c2, x, i)
x += foo_iface(c3, x, i)
x += foo_iface(c4, x, i)
x += foo_iface(c5, x, i)
x += foo_iface(c6, x, i)
x += foo_iface(c7, x, i)
x += foo_iface(c8, x, i)
x += foo_iface(c9, x, i)
}
return x
}
}
@@ -0,0 +1,106 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
open class ClassArrayBenchmark {
private var _data: Array<Value>? = null
val data: Array<Value>
get() = _data!!
init {
val list = ArrayList<Value>(BENCHMARK_SIZE)
for (n in classValues(BENCHMARK_SIZE))
list.add(n)
_data = list.toTypedArray()
}
//Benchmark
fun copy(): List<Value> {
return data.toList()
}
//Benchmark
fun copyManual(): List<Value> {
val list = ArrayList<Value>(data.size)
for (item in data) {
list.add(item)
}
return list
}
//Benchmark
fun filterAndCount(): Int {
return data.filter { filterLoad(it) }.count()
}
//Benchmark
fun filterAndMap(): List<String> {
return data.filter { filterLoad(it) }.map { mapLoad(it) }
}
//Benchmark
fun filterAndMapManual(): ArrayList<String> {
val list = ArrayList<String>()
for (it in data) {
if (filterLoad(it)) {
val value = mapLoad(it)
list.add(value)
}
}
return list
}
//Benchmark
fun filter(): List<Value> {
return data.filter { filterLoad(it) }
}
//Benchmark
fun filterManual(): List<Value> {
val list = ArrayList<Value>()
for (it in data) {
if (filterLoad(it))
list.add(it)
}
return list
}
//Benchmark
fun countFilteredManual(): Int {
var count = 0
for (it in data) {
if (filterLoad(it))
count++
}
return count
}
//Benchmark
fun countFiltered(): Int {
return data.count { filterLoad(it) }
}
//Benchmark
fun countFilteredLocal(): Int {
return data.cnt { filterLoad(it) }
}
//Benchmark
// fun reduce(): Int {
// return data.fold(0) { acc, it -> if (filterLoad(it)) acc + 1 else acc }
// }
}
@@ -0,0 +1,79 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
import org.jetbrains.benchmarksLauncher.Blackhole
open class ClassBaselineBenchmark {
//Benchmark
fun consume() {
for (item in 1..BENCHMARK_SIZE) {
Blackhole.consume(Value(item))
}
}
//Benchmark
fun consumeField() {
val value = Value(0)
for (item in 1..BENCHMARK_SIZE) {
value.value = item
Blackhole.consume(value)
}
}
//Benchmark
fun allocateList(): List<Value> {
val list = ArrayList<Value>(BENCHMARK_SIZE)
return list
}
//Benchmark
fun allocateArray(): Array<Value?> {
val list = arrayOfNulls<Value>(BENCHMARK_SIZE)
return list
}
//Benchmark
fun allocateListAndFill(): List<Value> {
val list = ArrayList<Value>(BENCHMARK_SIZE)
for (item in 1..BENCHMARK_SIZE) {
list.add(Value(item))
}
return list
}
//Benchmark
fun allocateListAndWrite(): List<Value> {
val value = Value(0)
val list = ArrayList<Value>(BENCHMARK_SIZE)
for (item in 1..BENCHMARK_SIZE) {
list.add(value)
}
return list
}
//Benchmark
fun allocateArrayAndFill(): Array<Value?> {
val list = arrayOfNulls<Value>(BENCHMARK_SIZE)
var index = 0
for (item in 1..BENCHMARK_SIZE) {
list[index++] = Value(item)
}
return list
}
}
@@ -0,0 +1,136 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
open class ClassListBenchmark {
private var _data: ArrayList<Value>? = null
val data: ArrayList<Value>
get() = _data!!
init {
val list = ArrayList<Value>(BENCHMARK_SIZE)
for (n in classValues(BENCHMARK_SIZE))
list.add(n)
_data = list
}
//Benchmark
fun copy(): List<Value> {
return data.toList()
}
//Benchmark
fun copyManual(): List<Value> {
val list = ArrayList<Value>(data.size)
for (item in data) {
list.add(item)
}
return list
}
//Benchmark
fun filterAndCount(): Int {
return data.filter { filterLoad(it) }.count()
}
//Benchmark
fun filterAndCountWithLambda(): Int {
return data.filter { it.value % 2 == 0 }.count()
}
//Benchmark
fun filterWithLambda(): List<Value> {
return data.filter { it.value % 2 == 0 }
}
//Benchmark
fun mapWithLambda(): List<String> {
return data.map { it.toString() }
}
//Benchmark
fun countWithLambda(): Int {
return data.count { it.value % 2 == 0 }
}
//Benchmark
fun filterAndMapWithLambda(): List<String> {
return data.filter { it.value % 2 == 0 }.map { it.toString() }
}
//Benchmark
fun filterAndMapWithLambdaAsSequence(): List<String> {
return data.asSequence().filter { it.value % 2 == 0 }.map { it.toString() }.toList()
}
//Benchmark
fun filterAndMap(): List<String> {
return data.filter { filterLoad(it) }.map { mapLoad(it) }
}
//Benchmark
fun filterAndMapManual(): ArrayList<String> {
val list = ArrayList<String>()
for (it in data) {
if (filterLoad(it)) {
val value = mapLoad(it)
list.add(value)
}
}
return list
}
//Benchmark
fun filter(): List<Value> {
return data.filter { filterLoad(it) }
}
//Benchmark
fun filterManual(): List<Value> {
val list = ArrayList<Value>()
for (it in data) {
if (filterLoad(it))
list.add(it)
}
return list
}
//Benchmark
fun countFilteredManual(): Int {
var count = 0
for (it in data) {
if (filterLoad(it))
count++
}
return count
}
//Benchmark
fun countFiltered(): Int {
return data.count { filterLoad(it) }
}
//Benchmark
// fun countFilteredLocal(): Int {
// return data.cnt { filterLoad(it) }
// }
//Benchmark
fun reduce(): Int {
return data.fold(0) { acc, it -> if (filterLoad(it)) acc + 1 else acc }
}
}
@@ -0,0 +1,103 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
import org.jetbrains.benchmarksLauncher.Blackhole
open class ClassStreamBenchmark {
private var _data: Iterable<Value>? = null
val data: Iterable<Value>
get() = _data!!
init {
_data = classValues(BENCHMARK_SIZE)
}
//Benchmark
fun copy(): List<Value> {
return data.asSequence().toList()
}
//Benchmark
fun copyManual(): List<Value> {
val list = ArrayList<Value>()
for (item in data.asSequence()) {
list.add(item)
}
return list
}
//Benchmark
fun filterAndCount(): Int {
return data.asSequence().filter { filterLoad(it) }.count()
}
//Benchmark
fun filterAndMap() {
for (item in data.asSequence().filter { filterLoad(it) }.map { mapLoad(it) })
Blackhole.consume(item)
}
//Benchmark
fun filterAndMapManual() {
for (it in data.asSequence()) {
if (filterLoad(it)) {
val item = mapLoad(it)
Blackhole.consume(item)
}
}
}
//Benchmark
fun filter() {
for (item in data.asSequence().filter { filterLoad(it) })
Blackhole.consume(item)
}
//Benchmark
fun filterManual(){
for (it in data.asSequence()) {
if (filterLoad(it))
Blackhole.consume(it)
}
}
//Benchmark
fun countFilteredManual(): Int {
var count = 0
for (it in data.asSequence()) {
if (filterLoad(it))
count++
}
return count
}
//Benchmark
fun countFiltered(): Int {
return data.asSequence().count { filterLoad(it) }
}
//Benchmark
// fun countFilteredLocal(): Int {
// return data.asSequence().cnt { filterLoad(it) }
// }
//Benchmark
fun reduce(): Int {
return data.asSequence().fold(0) {acc, it -> if (filterLoad(it)) acc + 1 else acc }
}
}
@@ -0,0 +1,30 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
open class CompanionObjectBenchmark {
//Benchmark
fun invokeRegularFunction() {
regularCompanionObjectFunction("")
}
companion object {
fun regularCompanionObjectFunction(o: Any): Any {
return o
}
}
}
@@ -0,0 +1,350 @@
package org.jetbrains.ring
import kotlin.experimental.and
class CoordinatesSolverBenchmark {
val solver: Solver
init {
val inputValue = """
12 5 3 25 3 9 3 9 1 3
13 3 12 6 10 10 12 2 10 10
9 2 9 5 6 12 5 0 2 10
10 14 12 5 3 9 5 2 10 10
8 1 3 9 4 0 3 14 10 10
12 0 4 6 9 6 12 5 6 10
11 12 3 9 6 9 5 3 9 6
8 5 6 8 3 12 7 10 10 11
12 3 13 6 12 3 9 6 12 2
13 4 5 5 5 6 12 5 5 2
1""".trimIndent()
val input = readTillParsed(inputValue)
solver = Solver(input!!)
}
data class Coordinate(val x: Int, val y: Int)
@SinceKotlin("1.1")
data class Field(val x: Int, val y: Int, val value: Byte) {
fun northWall(): Boolean {
return value and 1 != 0.toByte()
}
fun eastWall(): Boolean {
return value and 2 != 0.toByte()
}
fun southWall(): Boolean {
return value and 4 != 0.toByte()
}
fun westWall(): Boolean {
return value and 8 != 0.toByte()
}
fun hasObject(): Boolean {
return value and 16 != 0.toByte()
}
}
class Input(val labyrinth: Labyrinth, val nObjects: Int)
class Labyrinth(val width: Int, val height: Int, val fields: Array<Field>) {
fun getField(x: Int, y: Int): Field {
return fields[x + y * width]
}
}
class Output(val steps: List<Coordinate?>)
class InputParser {
private val rows : MutableList<Array<Field>> = mutableListOf()
private var numObjects: Int = 0
private val input: Input
get() {
val width = rows[0].size
val fields = arrayOfNulls<Field>(width * rows.size)
for (y in rows.indices) {
val row = rows[y]
for (p in y*width until y*width + width) {
fields[p] = row[p-y*width]
}
}
val labyrinth = Labyrinth(width, rows.size, fields.requireNoNulls())
return Input(labyrinth, numObjects)
}
fun feedLine(line: String): Input? {
val items = line.split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
if (items.size == 1) {
numObjects = items[0].toInt()
return input
} else if (items.size > 0) {
val rowNum = rows.size
val row = arrayOfNulls<Field>(items.size)
for (col in items.indices) {
row[col] = Field(rowNum, col, items[col].toByte())
}
rows.add(row.requireNoNulls())
}
return null
}
}
class Solver(private val input: Input) {
private val objects: List<Coordinate>
private val width: Int
private val height: Int
private val maze_end: Coordinate
private var counter: Long = 0
init {
objects = ArrayList()
for (f in input.labyrinth.fields) {
if (f.hasObject()) {
objects.add(Coordinate(f.x, f.y))
}
}
width = input.labyrinth.width
height = input.labyrinth.height
maze_end = Coordinate(width - 1, height - 1)
}
fun solve(): Output {
val steps = ArrayList<Coordinate>()
for (o in objects.indices) {
var limit = input.labyrinth.width + input.labyrinth.height - 2
var ss: List<Coordinate>? = null
while (ss == null) {
if (o == 0) {
ss = solveWithLimit(limit, MAZE_START) { it[it.size - 1] == objects[0] }
} else {
ss = solveWithLimit(limit, objects[o - 1]) { it[it.size - 1] == objects[o] }
}
if (ss != null) {
steps.addAll(ss)
}
limit++
}
}
var limit = input.labyrinth.width + input.labyrinth.height - 2
var ss: List<Coordinate>? = null
while (ss == null) {
ss = solveWithLimit(limit, objects[objects.size - 1]) { it[it.size - 1] == maze_end }
if (ss != null) {
steps.addAll(ss)
}
limit++
}
return createOutput(steps)
}
private fun createOutput(steps: List<Coordinate>): Output {
val objects : MutableList<Coordinate> = this.objects.toMutableList()
val outSteps : MutableList<Coordinate?> = mutableListOf()
for (step in steps) {
outSteps.add(step)
if (objects.contains(step)) {
outSteps.add(null)
objects.remove(step)
}
}
return Output(outSteps)
}
private fun isValid(steps: List<Coordinate>): Boolean {
counter++
val (x, y) = steps[steps.size - 1]
return if (!(x == input.labyrinth.width - 1 && y == input.labyrinth.height - 1)) { // Jobb also a cel
false
} else steps.containsAll(objects)
}
private fun getPossibleSteps(now: Coordinate, previous: Coordinate?): ArrayList<Coordinate> {
val field = input.labyrinth.getField(now.x, now.y)
val possibleSteps = ArrayList<Coordinate>()
if (now.x != width - 1 && !field.eastWall()) {
possibleSteps.add(Coordinate(now.x + 1, now.y))
}
if (now.x != 0 && !field.westWall()) {
possibleSteps.add(Coordinate(now.x - 1, now.y))
}
if (now.y != 0 && !field.northWall()) {
possibleSteps.add(Coordinate(now.x, now.y - 1))
}
if (now.y != height - 1 && !field.southWall()) {
possibleSteps.add(Coordinate(now.x, now.y + 1))
}
if (!field.hasObject() && previous != null) {
possibleSteps.remove(previous)
}
return possibleSteps
}
private fun solveWithLimit(limit: Int, start: Coordinate, validFn: (List<Coordinate>) -> Boolean): List<Coordinate>? {
var steps: MutableList<Coordinate>? = findFirstLegitSteps(null, start, limit)
while (steps != null && !validFn(steps)) {
steps = alter(start, null, steps)
}
return steps
}
private fun findFirstLegitSteps(startPrev: Coordinate?, start: Coordinate, num: Int): MutableList<Coordinate>? {
var steps: MutableList<Coordinate>? = ArrayList()
var i = 0
while (i < num) {
val prev: Coordinate?
val state: Coordinate
if (i == 0) {
state = start
prev = startPrev
} else if (i == 1) {
state = steps!![i - 1]
prev = startPrev
} else {
state = steps!![i - 1]
prev = steps[i - 2]
}
val possibleSteps = getPossibleSteps(state, prev)
if (possibleSteps.size == 0) {
if (steps!!.size == 0) {
return null
}
steps = alter(start, startPrev, steps)
if (steps == null) {
return null
}
i--
i++
continue
}
val newStep = possibleSteps[0]
steps!!.add(newStep)
i++
}
return steps
}
private fun alter(start: Coordinate, startPrev: Coordinate?, steps: MutableList<Coordinate>): MutableList<Coordinate>? {
val size = steps.size
var i = size - 1
while (i >= 0) {
val current = steps[i]
val prev = if (i == 0) start else steps[i - 1]
val prevprev: Coordinate?
if (i > 1) {
prevprev = steps[i - 2]
} else if (i == 1) {
prevprev = start
} else {
prevprev = startPrev
}
val alternatives = getPossibleSteps(prev, prevprev)
val index = alternatives.indexOf(current)
if (index != alternatives.size - 1) {
val newItem = alternatives[index + 1]
steps[i] = newItem
val remainder = findFirstLegitSteps(prev, newItem, size - i - 1)
if (remainder == null) {
i++
i--
continue
}
removeAfterIndexExclusive(steps, i)
steps.addAll(remainder)
return steps
} else {
if (i == 0) {
return null
}
}
i--
}
return steps
}
companion object {
private val MAZE_START = Coordinate(0, 0)
private fun removeAfterIndexExclusive(list: MutableList<*>, index: Int) {
val rnum = list.size - 1 - index
for (i in 0 until rnum) {
list.removeAt(list.size - 1)
}
}
}
}
private fun readTillParsed(inputValue: String): Input? {
val parser = InputParser()
var input: Input? = null
inputValue.lines().forEach { line ->
input = parser.feedLine(line)
}
return input
}
fun solve() {
val output = solver.solve()
for (c in output.steps) {
val value = if (c == null) {
"felvesz"
} else {
"${c.x} ${c.y}"
}
}
}
}
@@ -0,0 +1,100 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
fun classValues(size: Int): Iterable<Value> {
return intValues(size).map { Value(it) }
}
fun stringValues(size: Int): Iterable<String> {
return intValues(size).map { it.toString() }
}
fun intValues(size: Int): Iterable<Int> {
return 1..size
}
open class Value(var value: Int) {
val text = value.toString().reversed()
}
fun filterLoad(v: Value): Boolean {
return v.value.toString() in v.text
}
fun mapLoad(v: Value): String = v.text.reversed()
fun filterLoad(v: Int): Boolean {
return v.toString() in "0123456789"
}
fun mapLoad(v: Int): String = v.toString()
fun filterSome(v: Int): Boolean = v % 7 == 0 || v % 11 == 0
fun filterPrime(v: Int): Boolean {
if (v <= 1)
return false
if (v <= 3)
return true
if (v % 2 == 0)
return false
var i = 3
while (i*i <= v) {
if (v % i == 0)
return false
i += 2
}
return true
}
inline fun Array<Value>.cnt(predicate: (Value) -> Boolean): Int {
var count = 0
for (element in this) {
if (predicate(element))
count++
}
return count
}
inline fun IntArray.cnt(predicate: (Int) -> Boolean): Int {
var count = 0
for (element in this) {
if (predicate(element))
count++
}
return count
}
inline fun Iterable<Int>.cnt(predicate: (Int) -> Boolean): Int {
var count = 0
for (element in this) {
if (predicate(element))
count++
}
return count
}
inline fun Sequence<Int>.cnt(predicate: (Int) -> Boolean): Int {
var count = 0
for (element in this) {
if (predicate(element))
count++
}
return count
}
@@ -0,0 +1,82 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
import org.jetbrains.benchmarksLauncher.Random
/**
* Created by Mikhail.Glukhikh on 10/03/2015.
*
* Tests performance for function calls with default parameters
*/
open class DefaultArgumentBenchmark {
private var arg = 0
init {
arg = Random.nextInt()
}
fun sumTwo(first: Int, second: Int = 0): Int {
return first + second
}
fun sumFour(first: Int, second: Int = 0, third: Int = 1, fourth: Int = third): Int {
return first + second + third + fourth
}
fun sumEight(first: Int, second: Int = 0, third: Int = 1, fourth: Int = third,
fifth: Int = fourth, sixth: Int = fifth, seventh: Int = second, eighth: Int = seventh): Int {
return first + second + third + fourth + fifth + sixth + seventh + eighth
}
//Benchmark
fun testOneOfTwo() {
sumTwo(arg)
}
//Benchmark
fun testTwoOfTwo() {
sumTwo(arg, arg)
}
//Benchmark
fun testOneOfFour() {
sumFour(arg)
}
//Benchmark
fun testFourOfFour() {
sumFour(arg, arg, arg, arg)
}
//Benchmark
fun testOneOfEight() {
sumEight(arg)
}
//Benchmark
fun testEightOfEight() {
sumEight(arg, arg, arg, arg, arg, arg, arg, arg)
}
}
@@ -0,0 +1,53 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
import org.jetbrains.benchmarksLauncher.Blackhole
import org.jetbrains.benchmarksLauncher.Random
open class ElvisBenchmark {
class Value(var value: Int)
var array : Array<Value?> = arrayOf()
init {
array = Array(BENCHMARK_SIZE) {
if (Random.nextInt(BENCHMARK_SIZE) < BENCHMARK_SIZE / 10) null else Value(Random.nextInt())
}
}
//Benchmark
fun testElvis() {
for (obj in array) {
Blackhole.consume(obj?.value ?: 0)
}
}
class Composite(val x : Int, val y : Composite?)
fun check(a : Composite?) : Int {
return a?.y?.x ?: (a?.x ?: 3)
}
fun testCompositeElvis(): Int {
var result = 0
for (i in 0..BENCHMARK_SIZE)
result += check(Composite(Random.nextInt(), Composite(Random.nextInt(), null)))
return result
}
}
@@ -0,0 +1,210 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
fun fibonacci(): Sequence<Int> {
var a = 0
var b = 1
fun next(): Int {
val res = a + b
a = b
b = res
return res
}
return generateSequence { next() }
}
fun Any.isPalindrome() = toString() == toString().reversed()
inline fun IntRange.sum(predicate: (Int) -> Boolean): Int {
var sum = 0
for (i in this) if (predicate(i)) sum += i
return sum
}
inline fun Sequence<Int>.sum(predicate: (Int) -> Boolean): Int {
var sum = 0
for (i in this) if (predicate(i)) sum += i
return sum
}
/**
* A class tests decisions of various Euler problems
*
* NB: all tests here work slower than Java, probably because of all these functional wrappers
*/
open class EulerBenchmark {
//Benchmark
fun problem1bySequence() = (1..BENCHMARK_SIZE).asSequence().sum( { it % 3 == 0 || it % 5 == 0} )
//Benchmark
fun problem1() = (1..BENCHMARK_SIZE).sum( { it % 3 == 0 || it % 5 == 0} )
//Benchmark
fun problem2() = fibonacci().takeWhile { it < BENCHMARK_SIZE }.sum { it % 2 == 0 }
//Benchmark
fun problem4(): Long {
val s: Long = BENCHMARK_SIZE.toLong()
val maxLimit = (s-1)*(s-1)
val minLimit = (s/10)*(s/10)
val maxDiv = BENCHMARK_SIZE-1
val minDiv = BENCHMARK_SIZE/10
for (i in maxLimit downTo minLimit) {
if (!i.isPalindrome()) continue;
for (j in minDiv..maxDiv) {
if (i % j == 0L) {
val res = i / j
if (res in minDiv.toLong()..maxDiv.toLong()) {
return i
}
}
}
}
return -1
}
private val veryLongNumber = """
73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
05886116467109405077541002256983155200055935729725
71636269561882670428252483600823257530420752963450
"""
//Benchmark
fun problem8(): Long {
val productSize = when(BENCHMARK_SIZE) {
in 1..10 -> 4
in 11..1000 -> 8
else -> 13
}
val digits: MutableList<Int> = ArrayList()
for (digit in veryLongNumber) {
if (digit in '0'..'9') {
digits.add(digit.toInt() - '0'.toInt())
}
}
var largest = 0L
for (i in 0..digits.size -productSize-1) {
var product = 1L
for (j in 0..productSize-1) {
product *= digits[i+j]
}
if (product > largest) largest = product
}
return largest
}
//Benchmark
fun problem9(): Long {
val BENCHMARK_SIZE = BENCHMARK_SIZE // Looks awful but removes all implicit getSize() calls
for (c in BENCHMARK_SIZE/3..BENCHMARK_SIZE-3) {
val c2 = c.toLong() * c.toLong()
for (b in (BENCHMARK_SIZE-c)/2..c-1) {
if (b+c >= BENCHMARK_SIZE)
break
val a = BENCHMARK_SIZE - b - c
if (a >= b)
continue
val b2 = b.toLong() * b.toLong()
val a2 = a.toLong() * a.toLong()
if (c2 == b2 + a2) {
return a.toLong() * b.toLong() * c.toLong()
}
}
}
return -1L
}
data class Children(val left: Int, val right: Int)
//Benchmark
fun problem14(): List<Int> {
// Simplified problem is solved here: it's not allowed to leave the interval [0..BENCHMARK_SIZE) inside a number chain
val BENCHMARK_SIZE = BENCHMARK_SIZE
// Build a tree
// index is produced from first & second
val tree = Array(BENCHMARK_SIZE, { i -> Children(i*2, if (i>4 && (i+2) % 6 == 0) (i-1)/3 else 0)})
// Find longest chain by DFS
fun dfs(begin: Int): List<Int> {
if (begin == 0 || begin >= BENCHMARK_SIZE)
return listOf()
val left = dfs(tree[begin].left)
val right = dfs(tree[begin].right)
return listOf(begin) + if (left.size > right.size) left else right
}
return dfs(1)
}
data class Way(val length: Int, val next: Int)
//Benchmark
fun problem14full(): List<Int> {
val BENCHMARK_SIZE = BENCHMARK_SIZE
// Previous achievements: map (number) -> (length, next)
val map: MutableMap<Int, Way> = HashMap()
// Starting point
map.put(1, Way(0, 0))
// Check all other numbers
var bestNum = 0
var bestLen = 0
fun go(begin: Int): Way {
val res = map[begin]
if (res != null)
return res
val next = if (begin % 2 == 0) begin/2 else 3*begin+1
val childRes = go(next)
val myRes = Way(childRes.length + 1, next)
map[begin] = myRes
return myRes
}
for (i in 2..BENCHMARK_SIZE-1) {
val res = go(i)
if (res.length > bestLen) {
bestLen = res.length
bestNum = i
}
}
fun unroll(begin: Int): List<Int> {
if (begin == 0)
return listOf()
val next = map[begin]?.next ?: 0
return listOf(begin) + unroll(next)
}
return unroll(bestNum)
}
}
@@ -0,0 +1,86 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
/**
* This test checks work with long numbers using Fibonacci sequence
*
* NB: all three tests here work CRITICALLY (x4...x6) slower than their Java equivalents
* The reason is iteration on a progression formed as max downTo min or min..max step s.
* In case of a range min..max primitive types are used by the Kotlin compiler,
* but when we have a progression it's used directly with its iterator and so.
*/
open class FibonacciBenchmark {
//Benchmark
fun calcClassic(): Long {
var a = 1L
var b = 2L
val size = BENCHMARK_SIZE
for (i in 0..size-1) {
val next = a + b
a = b
b = next
}
return b
}
//Benchmark
fun calc(): Long {
// This test works CRITICALLY slower compared with java equivalent (05.03.2015)
var a = 1L
var b = 2L
// Probably for with downTo is the reason of slowness
for (i in BENCHMARK_SIZE downTo 1) {
val next = a + b
a = b
b = next
}
return b
}
//Benchmark
fun calcWithProgression(): Long {
// This test works CRITICALLY slower compared with java equivalent (05.03.2015)
var a = 1L
var b = 2L
// Probably for with step is the reason of slowness
for (i in 1..2*BENCHMARK_SIZE-1 step 2) {
val next = a + b
a = b
b = next
}
return b
}
//Benchmark
fun calcSquare(): Long {
// This test works CRITICALLY slower compared with java equivalent (05.03.2015)
var a = 1L
var b = 2L
val s = BENCHMARK_SIZE.toLong()
val limit = s*s
// Probably for with downTo is the reason of slowness
for (i in limit downTo 1) {
val next = a + b
a = b
b = next
}
return b
}
}
@@ -0,0 +1,104 @@
package org.jetbrains.ring
class ForLoopsBenchmark {
private val array: Array<Int> = Array(BENCHMARK_SIZE) {
it
}
private val intArray: IntArray = IntArray(BENCHMARK_SIZE) {
it
}
private val charArray: CharArray = CharArray(BENCHMARK_SIZE) {
it.toChar()
}
private val string: String = charArray.joinToString()
private val floatArray: FloatArray = FloatArray(BENCHMARK_SIZE) {
it.toFloat()
}
fun arrayLoop(): Long {
var sum = 0L
for (e in array) {
sum += e
}
return sum
}
fun intArrayLoop(): Long {
var sum = 0L
for (e in intArray) {
sum += e
}
return sum
}
fun charArrayLoop(): Long {
var sum = 0L
for (e in charArray) {
sum += e.toLong()
}
return sum
}
fun stringLoop(): Long {
var sum = 0L
for (e in string) {
sum += e.hashCode()
}
return sum
}
fun floatArrayLoop(): Double {
var sum = 0.0
for (e in floatArray) {
sum += e
}
return sum
}
// Iterations over .indices
fun arrayIndicesLoop(): Long {
var sum = 0L
for (i in array.indices) {
sum += array[i]
}
return sum
}
fun intArrayIndicesLoop(): Long {
var sum = 0L
for (i in intArray.indices) {
sum += intArray[i]
}
return sum
}
fun charArrayIndicesLoop(): Long {
var sum = 0L
for (i in charArray.indices) {
sum += charArray[i].toLong()
}
return sum
}
fun stringIndicesLoop(): Long {
var sum = 0L
for (i in string.indices) {
sum += string[i].hashCode()
}
return sum
}
fun floatArrayIndicesLoop(): Double {
var sum = 0.0
for (i in floatArray.indices) {
sum += floatArray[i]
}
return sum
}
}
@@ -0,0 +1,508 @@
/*
* 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.ring
private const val RUNS = 1_000_000
open class InheritanceBenchmark {
open class A() {
fun a(): Int = 0
fun a1(): Int = 1
fun a2(): Int = 2
fun a3(): Int = 3
fun a4(): Int = 4
fun a5(): Int = 5
fun a6(): Int = 6
fun a7(): Int = 7
fun a8(): Int = 8
open fun a9(): Int = 9
open fun a10(): Int = 10
open fun a11(): Int = 11
open fun a12(): Int = 12
open fun a13(): Int = 13
open fun a14(): Int = 14
open fun a15(): Int = 15
open fun a16(): Int = 16
open fun a17(): Int = 17
open fun a18(): Int = 18
open fun a19(): Int = 19
open fun a20(): Int = 20
open fun a21(): Int = 21
open fun a22(): Int = 22
open fun a23(): Int = 23
open fun a24(): Int = 24
open fun a25(): Int = 25
open fun a26(): Int = 26
open fun a27(): Int = 27
open fun a28(): Int = 28
open fun a29(): Int = 29
open fun a30(): Int = 30
open fun a31(): Int = 31
open fun a32(): Int = 32
open fun a33(): Int = 33
open fun a34(): Int = 34
open fun a35(): Int = 35
open fun a36(): Int = 36
open fun a37(): Int = 37
open fun a38(): Int = 38
open fun a39(): Int = 39
open fun a40(): Int = 40
open fun a41(): Int = 41
open fun a42(): Int = 42
open fun a43(): Int = 43
open fun a44(): Int = 44
open fun a45(): Int = 45
open fun a46(): Int = 46
open fun a47(): Int = 47
open fun a48(): Int = 48
open fun a49(): Int = 49
open fun a50(): Int = 50
open fun a51(): Int = 51
open fun a52(): Int = 52
open fun a53(): Int = 53
open fun a54(): Int = 54
open fun a55(): Int = 55
open fun a56(): Int = 56
open fun a57(): Int = 57
open fun a58(): Int = 58
open fun a59(): Int = 59
open fun a60(): Int = 60
open fun a61(): Int = 61
open fun a62(): Int = 62
open fun a63(): Int = 63
open fun a64(): Int = 64
open fun a65(): Int = 65
open fun a66(): Int = 66
open fun a67(): Int = 67
open fun a68(): Int = 68
open fun a69(): Int = 69
open fun a70(): Int = 70
open fun a71(): Int = 71
open fun a72(): Int = 72
open fun a73(): Int = 73
open fun a74(): Int = 74
open fun a75(): Int = 75
open fun a76(): Int = 76
open fun a77(): Int = 77
open fun a78(): Int = 78
open fun a79(): Int = 79
open fun a80(): Int = 80
open fun a81(): Int = 81
open fun a82(): Int = 82
open fun a83(): Int = 83
open fun a84(): Int = 84
open fun a85(): Int = 85
open fun a86(): Int = 86
open fun a87(): Int = 87
open fun a88(): Int = 88
open fun a89(): Int = 89
open fun a90(): Int = 90
open fun a91(): Int = 91
open fun a92(): Int = 92
open fun a93(): Int = 93
open fun a94(): Int = 94
open fun a95(): Int = 95
open fun a96(): Int = 96
open fun a97(): Int = 97
open fun a98(): Int = 98
open fun a99(): Int = 99
}
open class B() : A() {
override fun a10(): Int = 0
fun b1(): Int = 1
fun b2(): Int = 2
fun b3(): Int = 3
fun b4(): Int = 4
fun b5(): Int = 5
open fun b6(): Int = 6
open fun b7(): Int = 7
open fun b8(): Int = 8
open fun b9(): Int = 9
open fun b10(): Int = 10
open fun b11(): Int = 11
open fun b12(): Int = 12
open fun b13(): Int = 13
open fun b14(): Int = 14
open fun b15(): Int = 15
open fun b16(): Int = 16
open fun b17(): Int = 17
open fun b18(): Int = 18
open fun b19(): Int = 19
open fun b20(): Int = 20
open fun b21(): Int = 21
open fun b22(): Int = 22
open fun b23(): Int = 23
open fun b24(): Int = 24
open fun b25(): Int = 25
open fun b26(): Int = 26
open fun b27(): Int = 27
open fun b28(): Int = 28
open fun b29(): Int = 29
open fun b30(): Int = 30
open fun b31(): Int = 31
open fun b32(): Int = 32
open fun b33(): Int = 33
open fun b34(): Int = 34
open fun b35(): Int = 35
open fun b36(): Int = 36
open fun b37(): Int = 37
open fun b38(): Int = 38
open fun b39(): Int = 39
open fun b40(): Int = 40
open fun b41(): Int = 41
open fun b42(): Int = 42
open fun b43(): Int = 43
open fun b44(): Int = 44
open fun b45(): Int = 45
open fun b46(): Int = 46
open fun b47(): Int = 47
open fun b48(): Int = 48
open fun b49(): Int = 49
open fun b50(): Int = 50
open fun b51(): Int = 51
open fun b52(): Int = 52
open fun b53(): Int = 53
open fun b54(): Int = 54
open fun b55(): Int = 55
open fun b56(): Int = 56
open fun b57(): Int = 57
open fun b58(): Int = 58
open fun b59(): Int = 59
open fun b60(): Int = 60
open fun b61(): Int = 61
open fun b62(): Int = 62
open fun b63(): Int = 63
open fun b64(): Int = 64
open fun b65(): Int = 65
open fun b66(): Int = 66
open fun b67(): Int = 67
open fun b68(): Int = 68
open fun b69(): Int = 69
open fun b70(): Int = 70
open fun b71(): Int = 71
open fun b72(): Int = 72
open fun b73(): Int = 73
open fun b74(): Int = 74
open fun b75(): Int = 75
open fun b76(): Int = 76
open fun b77(): Int = 77
open fun b78(): Int = 78
open fun b79(): Int = 79
open fun b80(): Int = 80
open fun b81(): Int = 81
open fun b82(): Int = 82
open fun b83(): Int = 83
open fun b84(): Int = 84
open fun b85(): Int = 85
open fun b86(): Int = 86
open fun b87(): Int = 87
open fun b88(): Int = 88
open fun b89(): Int = 89
open fun b90(): Int = 90
open fun b91(): Int = 91
open fun b92(): Int = 92
open fun b93(): Int = 93
open fun b94(): Int = 94
open fun b95(): Int = 95
open fun b96(): Int = 96
open fun b97(): Int = 97
open fun b98(): Int = 98
open fun b99(): Int = 99
}
open class C() : B() {
fun c(): Int = 0
override fun a10(): Int = 100
fun c1(): Int = 1
fun c2(): Int = 2
fun c3(): Int = 3
fun c4(): Int = 4
fun c5(): Int = 5
fun c6(): Int = 6
fun c7(): Int = 7
fun c8(): Int = 8
open fun c9(): Int = 9
open fun c10(): Int = 10
open fun c11(): Int = 11
open fun c12(): Int = 12
open fun c13(): Int = 13
open fun c14(): Int = 14
open fun c15(): Int = 15
open fun c16(): Int = 16
open fun c17(): Int = 17
open fun c18(): Int = 18
open fun c19(): Int = 19
open fun c20(): Int = 20
open fun c21(): Int = 21
open fun c22(): Int = 22
open fun c23(): Int = 23
open fun c24(): Int = 24
open fun c25(): Int = 25
open fun c26(): Int = 26
open fun c27(): Int = 27
open fun c28(): Int = 28
open fun c29(): Int = 29
open fun c30(): Int = 30
open fun c31(): Int = 31
open fun c32(): Int = 32
open fun c33(): Int = 33
open fun c34(): Int = 34
open fun c35(): Int = 35
open fun c36(): Int = 36
open fun c37(): Int = 37
open fun c38(): Int = 38
open fun c39(): Int = 39
open fun c40(): Int = 40
open fun c41(): Int = 41
open fun c42(): Int = 42
open fun c43(): Int = 43
open fun c44(): Int = 44
open fun c45(): Int = 45
open fun c46(): Int = 46
open fun c47(): Int = 47
open fun c48(): Int = 48
open fun c49(): Int = 49
open fun c50(): Int = 50
open fun c51(): Int = 51
open fun c52(): Int = 52
open fun c53(): Int = 53
open fun c54(): Int = 54
open fun c55(): Int = 55
open fun c56(): Int = 56
open fun c57(): Int = 57
open fun c58(): Int = 58
open fun c59(): Int = 59
open fun c60(): Int = 60
open fun c61(): Int = 61
open fun c62(): Int = 62
open fun c63(): Int = 63
open fun c64(): Int = 64
open fun c65(): Int = 65
open fun c66(): Int = 66
open fun c67(): Int = 67
open fun c68(): Int = 68
open fun c69(): Int = 69
open fun c70(): Int = 70
open fun c71(): Int = 71
open fun c72(): Int = 72
open fun c73(): Int = 73
open fun c74(): Int = 74
open fun c75(): Int = 75
open fun c76(): Int = 76
open fun c77(): Int = 77
open fun c78(): Int = 78
open fun c79(): Int = 79
open fun c80(): Int = 80
open fun c81(): Int = 81
open fun c82(): Int = 82
open fun c83(): Int = 83
open fun c84(): Int = 84
open fun c85(): Int = 85
open fun c86(): Int = 86
open fun c87(): Int = 87
open fun c88(): Int = 88
open fun c89(): Int = 89
open fun c90(): Int = 90
open fun c91(): Int = 91
open fun c92(): Int = 92
open fun c93(): Int = 93
open fun c94(): Int = 94
open fun c95(): Int = 95
open fun c96(): Int = 96
open fun c97(): Int = 97
open fun c98(): Int = 98
open fun c99(): Int = 99
}
open class D() : C() {
override fun a10(): Int = 1000
fun d(): Int = 0
fun d1(): Int = 1
fun d2(): Int = 2
fun d3(): Int = 3
fun d4(): Int = 4
fun d5(): Int = 5
fun d6(): Int = 6
fun d7(): Int = 7
fun d8(): Int = 8
open fun d9(): Int = 9
open fun d10(): Int = 10
open fun d11(): Int = 11
open fun d12(): Int = 12
open fun d13(): Int = 13
open fun d14(): Int = 14
open fun d15(): Int = 15
open fun d16(): Int = 16
open fun d17(): Int = 17
open fun d18(): Int = 18
open fun d19(): Int = 19
open fun d20(): Int = 20
open fun d21(): Int = 21
open fun d22(): Int = 22
open fun d23(): Int = 23
open fun d24(): Int = 24
open fun d25(): Int = 25
open fun d26(): Int = 26
open fun d27(): Int = 27
open fun d28(): Int = 28
open fun d29(): Int = 29
open fun d30(): Int = 30
open fun d31(): Int = 31
open fun d32(): Int = 32
open fun d33(): Int = 33
open fun d34(): Int = 34
open fun d35(): Int = 35
open fun d36(): Int = 36
open fun d37(): Int = 37
open fun d38(): Int = 38
open fun d39(): Int = 39
open fun d40(): Int = 40
open fun d41(): Int = 41
open fun d42(): Int = 42
open fun d43(): Int = 43
open fun d44(): Int = 44
open fun d45(): Int = 45
open fun d46(): Int = 46
open fun d47(): Int = 47
open fun d48(): Int = 48
open fun d49(): Int = 49
open fun d50(): Int = 50
open fun d51(): Int = 51
open fun d52(): Int = 52
open fun d53(): Int = 53
open fun d54(): Int = 54
open fun d55(): Int = 55
open fun d56(): Int = 56
open fun d57(): Int = 57
open fun d58(): Int = 58
open fun d59(): Int = 59
open fun d60(): Int = 60
open fun d61(): Int = 61
open fun d62(): Int = 62
open fun d63(): Int = 63
open fun d64(): Int = 64
open fun d65(): Int = 65
open fun d66(): Int = 66
open fun d67(): Int = 67
open fun d68(): Int = 68
open fun d69(): Int = 69
open fun d70(): Int = 70
open fun d71(): Int = 71
open fun d72(): Int = 72
open fun d73(): Int = 73
open fun d74(): Int = 74
open fun d75(): Int = 75
open fun d76(): Int = 76
open fun d77(): Int = 77
open fun d78(): Int = 78
open fun d79(): Int = 79
open fun d80(): Int = 80
open fun d81(): Int = 81
open fun d82(): Int = 82
open fun d83(): Int = 83
open fun d84(): Int = 84
open fun d85(): Int = 85
open fun d86(): Int = 86
open fun d87(): Int = 87
open fun d88(): Int = 88
open fun d89(): Int = 89
open fun d90(): Int = 90
open fun d91(): Int = 91
open fun d92(): Int = 92
open fun d93(): Int = 93
open fun d94(): Int = 94
open fun d95(): Int = 95
open fun d96(): Int = 96
open fun d97(): Int = 97
open fun d98(): Int = 98
open fun d99(): Int = 99
}
open class E() : D() {
override fun a10(): Int = 200
open fun e1(): Int = 1
open fun e2(): Int = 2
open fun e3(): Int = 3
open fun e4(): Int = 4
open fun e5(): Int = 5
open fun e6(): Int = 6
open fun e7(): Int = 7
open fun e8(): Int = 8
open fun e9(): Int = 9
open fun e10(): Int = 10
open fun e11(): Int = 11
open fun e12(): Int = 12
open fun e13(): Int = 13
open fun e14(): Int = 14
open fun e15(): Int = 15
}
open class F() : E() {
open fun f1(): Int = 1
open fun f2(): Int = 2
open fun f3(): Int = 3
open fun f4(): Int = 4
open fun f5(): Int = 5
open fun f6(): Int = 6
open fun f7(): Int = 7
open fun f8(): Int = 8
open fun f9(): Int = 9
open fun f10(): Int = 10
open fun f11(): Int = 11
open fun f12(): Int = 12
open fun f13(): Int = 13
open fun f14(): Int = 14
open fun f15(): Int = 15
}
open class G() : F() {
open fun g1(): Int = 1
open fun g2(): Int = 2
open fun g3(): Int = 3
open fun g4(): Int = 4
open fun g5(): Int = 5
open fun g6(): Int = 6
open fun g7(): Int = 7
open fun g8(): Int = 8
open fun g9(): Int = 9
open fun g10(): Int = 10
open fun g11(): Int = 11
open fun g12(): Int = 12
open fun g13(): Int = 13
open fun g14(): Int = 14
open fun g15(): Int = 15
}
val a = A()
val b = B()
val c = C()
val d = D()
val e = E()
val f = F()
val g = G()
fun baseCalls(): Int {
var x = 0
for (i in 0 until RUNS) {
x += a.a()
x += b.a10()
x += c.b20()
x += d.c20()
x += e.d10()
x += f.e10()
x += g.f10()
x += g.g3()
}
return x
}
}
@@ -0,0 +1,73 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
fun load(value: Int, size: Int): Int {
var acc = 0
for (i in 0..size) {
acc = acc xor value.hashCode()
}
return acc
}
inline fun loadInline(value: Int, size: Int): Int {
var acc = 0
for (i in 0..size) {
acc = acc xor value.hashCode()
}
return acc
}
fun <T: Any> loadGeneric(value: T, size: Int): Int {
var acc = 0
for (i in 0..size) {
acc = acc xor value.hashCode()
}
return acc
}
inline fun <T: Any> loadGenericInline(value: T, size: Int): Int {
var acc = 0
for (i in 0..size) {
acc = acc xor value.hashCode()
}
return acc
}
open class InlineBenchmark {
private var value = 2138476523
//Benchmark
fun calculate(): Int {
return load(value, BENCHMARK_SIZE)
}
//Benchmark
fun calculateInline(): Int {
return loadInline(value, BENCHMARK_SIZE)
}
//Benchmark
fun calculateGeneric(): Int {
return loadGeneric(value, BENCHMARK_SIZE)
}
//Benchmark
fun calculateGenericInline(): Int {
return loadGenericInline(value, BENCHMARK_SIZE)
}
}
@@ -0,0 +1,171 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
open class IntArrayBenchmark {
private var _data: IntArray? = null
val data: IntArray
get() = _data!!
init {
val list = IntArray(BENCHMARK_SIZE)
var index = 0
for (n in intValues(BENCHMARK_SIZE))
list[index++] = n
_data = list
}
//Benchmark
fun copy(): List<Int> {
return data.toList()
}
//Benchmark
fun copyManual(): ArrayList<Int> {
val list = ArrayList<Int>(data.size)
for (item in data) {
list.add(item)
}
return list
}
//Benchmark
fun filterAndCount(): Int {
return data.filter { filterLoad(it) }.count()
}
//Benchmark
fun filterSomeAndCount(): Int {
return data.filter { filterSome(it) }.count()
}
//Benchmark
fun filterAndMap(): List<String> {
return data.filter { filterLoad(it) }.map { mapLoad(it) }
}
//Benchmark
fun filterAndMapManual(): ArrayList<String> {
val list = ArrayList<String>()
for (it in data) {
if (filterLoad(it)) {
val value = mapLoad(it)
list.add(value)
}
}
return list
}
//Benchmark
fun filter(): List<Int> {
return data.filter { filterLoad(it) }
}
//Benchmark
fun filterSome(): List<Int> {
return data.filter { filterSome(it) }
}
//Benchmark
fun filterPrime(): List<Int> {
return data.filter { filterPrime(it) }
}
//Benchmark
fun filterManual(): ArrayList<Int> {
val list = ArrayList<Int>()
for (it in data) {
if (filterLoad(it))
list.add(it)
}
return list
}
//Benchmark
fun filterSomeManual(): ArrayList<Int> {
val list = ArrayList<Int>()
for (it in data) {
if (filterSome(it))
list.add(it)
}
return list
}
//Benchmark
fun countFilteredManual(): Int {
var count = 0
for (it in data) {
if (filterLoad(it))
count++
}
return count
}
//Benchmark
fun countFilteredSomeManual(): Int {
var count = 0
for (it in data) {
if (filterSome(it))
count++
}
return count
}
//Benchmark
fun countFilteredPrimeManual(): Int {
var count = 0
for (it in data) {
if (filterPrime(it))
count++
}
return count
}
//Benchmark
fun countFiltered(): Int {
return data.count { filterLoad(it) }
}
//Benchmark
fun countFilteredSome(): Int {
return data.count { filterSome(it) }
}
//Benchmark
fun countFilteredPrime(): Int {
val res = data.count { filterPrime(it) }
//println(res)
return res
}
//Benchmark
fun countFilteredLocal(): Int {
return data.cnt { filterLoad(it) }
}
//Benchmark
fun countFilteredSomeLocal(): Int {
return data.cnt { filterSome(it) }
}
//Benchmark
fun reduce(): Int {
return data.fold(0) { acc, it -> if (filterLoad(it)) acc + 1 else acc }
}
}
@@ -0,0 +1,60 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
import org.jetbrains.benchmarksLauncher.Blackhole
open class IntBaselineBenchmark {
//Benchmark
fun consume() {
for (item in 1..BENCHMARK_SIZE) {
Blackhole.consume(item)
}
}
//Benchmark
fun allocateList(): List<Int> {
val list = ArrayList<Int>(BENCHMARK_SIZE)
return list
}
//Benchmark
fun allocateArray(): IntArray {
val list = IntArray(BENCHMARK_SIZE)
return list
}
//Benchmark
fun allocateListAndFill(): List<Int> {
val list = ArrayList<Int>(BENCHMARK_SIZE)
for (item in 1..BENCHMARK_SIZE) {
list.add(item)
}
return list
}
//Benchmark
fun allocateArrayAndFill(): IntArray {
var index = 0
val list = IntArray(BENCHMARK_SIZE)
for (item in 1..BENCHMARK_SIZE) {
list[index++] = item
}
return list
}
}
@@ -0,0 +1,106 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
open class IntListBenchmark {
private var _data: List<Int>? = null
val data: List<Int>
get() = _data!!
init {
val list = ArrayList<Int>(BENCHMARK_SIZE)
for (n in intValues(BENCHMARK_SIZE))
list.add(n)
_data = list
}
//Benchmark
fun copy(): List<Int> {
return data.toList()
}
//Benchmark
fun copyManual(): List<Int> {
val list = ArrayList<Int>(data.size)
for (item in data) {
list.add(item)
}
return list
}
//Benchmark
fun filterAndCount(): Int {
return data.filter { filterLoad(it) }.count()
}
//Benchmark
fun filterAndMap(): List<String> {
return data.filter { filterLoad(it) }.map { mapLoad(it) }
}
//Benchmark
fun filterAndMapManual(): ArrayList<String> {
val list = ArrayList<String>()
for (it in data) {
if (filterLoad(it)) {
val value = mapLoad(it)
list.add(value)
}
}
return list
}
//Benchmark
fun filter(): List<Int> {
return data.filter { filterLoad(it) }
}
//Benchmark
fun filterManual(): List<Int> {
val list = ArrayList<Int>()
for (it in data) {
if (filterLoad(it))
list.add(it)
}
return list
}
//Benchmark
fun countFilteredManual(): Int {
var count = 0
for (it in data) {
if (filterLoad(it))
count++
}
return count
}
//Benchmark
fun countFiltered(): Int {
return data.count { filterLoad(it) }
}
//Benchmark
fun countFilteredLocal(): Int {
return data.cnt { filterLoad(it) }
}
//Benchmark
fun reduce(): Int {
return data.fold(0) { acc, it -> if (filterLoad(it)) acc + 1 else acc }
}
}
@@ -0,0 +1,103 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
import org.jetbrains.benchmarksLauncher.Blackhole
open class IntStreamBenchmark {
private var _data: Iterable<Int>? = null
val data: Iterable<Int>
get() = _data!!
init {
_data = intValues(BENCHMARK_SIZE)
}
//Benchmark
fun copy(): List<Int> {
return data.asSequence().toList()
}
//Benchmark
fun copyManual(): List<Int> {
val list = ArrayList<Int>()
for (item in data.asSequence()) {
list.add(item)
}
return list
}
//Benchmark
fun filterAndCount(): Int {
return data.asSequence().filter { filterLoad(it) }.count()
}
//Benchmark
fun filterAndMap() {
for (item in data.asSequence().filter { filterLoad(it) }.map { mapLoad(it) })
Blackhole.consume(item)
}
//Benchmark
fun filterAndMapManual() {
for (it in data.asSequence()) {
if (filterLoad(it)) {
val item = mapLoad(it)
Blackhole.consume(item)
}
}
}
//Benchmark
fun filter() {
for (item in data.asSequence().filter { filterLoad(it) })
Blackhole.consume(item)
}
//Benchmark
fun filterManual(){
for (it in data.asSequence()) {
if (filterLoad(it))
Blackhole.consume(it)
}
}
//Benchmark
fun countFilteredManual(): Int {
var count = 0
for (it in data.asSequence()) {
if (filterLoad(it))
count++
}
return count
}
//Benchmark
fun countFiltered(): Int {
return data.asSequence().count { filterLoad(it) }
}
//Benchmark
fun countFilteredLocal(): Int {
return data.asSequence().cnt { filterLoad(it) }
}
//Benchmark
fun reduce(): Int {
return data.asSequence().fold(0) {acc, it -> if (filterLoad(it)) acc + 1 else acc }
}
}
@@ -0,0 +1,108 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
import org.jetbrains.benchmarksLauncher.Random
var globalAddendum = 0
open class LambdaBenchmark {
private inline fun <T> runLambda(x: () -> T): T = x()
private fun <T> runLambdaNoInline(x: () -> T): T = x()
init {
globalAddendum = Random.nextInt(20)
}
//Benchmark
fun noncapturingLambda(): Int {
var x: Int = 0
for (i in 0..BENCHMARK_SIZE) {
x += runLambda { globalAddendum }
}
return x
}
//Benchmark
fun noncapturingLambdaNoInline(): Int {
var x: Int = 0
for (i in 0..BENCHMARK_SIZE) {
x += runLambdaNoInline { globalAddendum }
}
return x
}
//Benchmark
fun capturingLambda(): Int {
val addendum = globalAddendum + 1
var x: Int = 0
for (i in 0..BENCHMARK_SIZE) {
x += runLambda { addendum }
}
return x
}
//Benchmark
fun capturingLambdaNoInline(): Int {
val addendum = globalAddendum + 1
var x: Int = 0
for (i in 0..BENCHMARK_SIZE) {
x += runLambdaNoInline { addendum }
}
return x
}
//Benchmark
fun mutatingLambda(): Int {
var x: Int = 0
for (i in 0..BENCHMARK_SIZE) {
runLambda { x += globalAddendum }
}
return x
}
//Benchmark
fun mutatingLambdaNoInline(): Int {
var x: Int = 0
for (i in 0..BENCHMARK_SIZE) {
runLambdaNoInline { x += globalAddendum }
}
return x
}
//Benchmark
fun methodReference(): Int {
var x: Int = 0
for (i in 0..BENCHMARK_SIZE) {
x += runLambda(::referenced)
}
return x
}
//Benchmark
fun methodReferenceNoInline(): Int {
var x: Int = 0
for (i in 0..BENCHMARK_SIZE) {
x += runLambdaNoInline(::referenced)
}
return x
}
}
private fun referenced(): Int {
return globalAddendum
}
@@ -0,0 +1,90 @@
/*
* 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.ring
import org.jetbrains.benchmarksLauncher.Random
class ChunkBuffer(var readPosition: Int, var writePosition: Int = readPosition + Random.nextInt(50)) {
private val nextRef: AtomicRef<ChunkBuffer?> = atomic(null)
/**
* Reference to next buffer view. Useful to chain multiple views.
* @see appendNext
* @see cleanNext
*/
var next: ChunkBuffer? get() = nextRef.value
set(newValue) {
if (newValue == null) {
cleanNext()
} else {
appendNext(newValue)
}
}
fun cleanNext(): ChunkBuffer? {
return nextRef.getAndSet(null)
}
private fun appendNext(chunk: ChunkBuffer) {
if (!nextRef.compareAndSet(null, chunk)) {
throw IllegalStateException("This chunk has already a next chunk.")
}
}
inline val readRemaining: Int get() = writePosition - readPosition
}
fun ChunkBuffer.remainingAll(): Long = remainingAll(0L)
private tailrec fun ChunkBuffer.remainingAll(n: Long): Long {
val rem = readRemaining.toLong() + n
val next = this.next ?: return rem
return next.remainingAll(rem)
}
class LinkedListOfBuffers(var head: ChunkBuffer = ChunkBuffer(0,0),
var remaining: Long = head.remainingAll()) {
var tailRemaining: Long = remaining - head.readRemaining
set(newValue) {
if (newValue < 0) {
error("tailRemaining is negative: $newValue")
}
val tailSize = head.next?.remainingAll() ?: 0L
if (newValue == 0L) {
if (tailSize != 0L) {
error("tailRemaining is set 0 while there is a tail of size $tailSize")
}
}
field = newValue
}
}
open class LinkedListWithAtomicsBenchmark {
val list: LinkedListOfBuffers
init {
val chunks: MutableList<ChunkBuffer> = ArrayList()
(0..BENCHMARK_SIZE/2).forEachIndexed { index, i ->
val chunk = ChunkBuffer(Random.nextInt())
chunks.add(chunk)
if (i > 0)
chunks[i - 1].next = chunk
}
list = LinkedListOfBuffers(chunks[0])
}
tailrec fun ensureNext(current: ChunkBuffer = list.head): ChunkBuffer? {
val next = current.next
return when {
next == null -> null
else -> {
list.tailRemaining = Random.nextInt().toLong() + 1
ensureNext(next)
}
}
}
}
@@ -0,0 +1,38 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
import org.jetbrains.benchmarksLauncher.Blackhole
open class LocalObjectsBenchmark {
//Benchmark
fun localArray(): Int {
val size = 48
val array = IntArray(size)
for (i in 1..size) {
array[i - 1] = i * 2
}
var result = 0
for (i in 0 until size) {
result += array[i]
}
if (result > 10) {
return 1
}
return 2
}
}
@@ -0,0 +1,80 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
import org.jetbrains.benchmarksLauncher.Blackhole
open class LoopBenchmark {
lateinit var arrayList: List<Value>
lateinit var array: Array<Value>
init {
val list = ArrayList<Value>(BENCHMARK_SIZE)
for (n in classValues(BENCHMARK_SIZE))
list.add(n)
arrayList = list
array = list.toTypedArray()
}
//Benchmark
fun arrayLoop() {
for (x in array) {
Blackhole.consume(x)
}
}
//Benchmark
fun arrayIndexLoop() {
for (i in array.indices) {
Blackhole.consume(array[i])
}
}
//Benchmark
fun rangeLoop() {
for (i in 0..BENCHMARK_SIZE) {
Blackhole.consume(i)
}
}
//Benchmark
fun arrayListLoop() {
for (x in arrayList) {
Blackhole.consume(x)
}
}
//Benchmark
fun arrayWhileLoop() {
var i = 0
val s = array.size
while (i < s) {
Blackhole.consume(array[i])
i++
}
}
//Benchmark
fun arrayForeachLoop() {
array.forEach { Blackhole.consume(it) }
}
//Benchmark
fun arrayListForeachLoop() {
arrayList.forEach { Blackhole.consume(it) }
}
}
@@ -0,0 +1,74 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
import org.jetbrains.benchmarksLauncher.Blackhole
import org.jetbrains.benchmarksLauncher.Random
/**
* This class emulates matrix behaviour using a hash map as its implementation
*/
class KMatrix internal constructor(val rows: Int, val columns: Int) {
private val matrix: MutableMap<Pair<Int, Int>, Double> = HashMap();
init {
for (row in 0..rows-1) {
for (col in 0..columns-1) {
matrix.put(Pair(row, col), Random.nextDouble())
}
}
}
fun get(row: Int, col: Int): Double {
return get(Pair(row, col))
}
fun get(pair: Pair<Int, Int>): Double {
return matrix.getOrElse(pair, { 0.0 })
}
fun put(pair: Pair<Int, Int>, elem: Double) {
matrix.put(pair, elem)
}
operator fun plusAssign(other: KMatrix) {
for (entry in matrix.entries) {
put(entry.key, entry.value + other.get(entry.key))
}
}
}
/**
* This class tests hash map performance
*/
open class MatrixMapBenchmark {
//Benchmark
fun add(): KMatrix {
var rows = BENCHMARK_SIZE
var cols = 1
while (rows > cols) {
rows /= 2
cols *= 2
}
val a = KMatrix(rows, cols)
val b = KMatrix(rows, cols)
a += b
return a
}
}
@@ -0,0 +1,49 @@
/**
* Created by semoro on 07.07.17.
*/
import org.jetbrains.benchmarksLauncher.assert
fun octoTest() {
val tree = OctoTree<Boolean>(4)
val to = (2 shl tree.depth)
var x = 0
var y = 0
var z = 0
while (x < to) {
y = 0
while (y < to) {
z = 0
while (z < to) {
val c = (z + to * y + to * to * x) % 2 == 0
tree.set(x, y, z, c)
z++
}
y++
}
x++
}
x = 0
y = 0
z = 0
while (x < to) {
y = 0
while (y < to) {
z = 0
while (z < to) {
val c = (z + to * y + to * to * x) % 2 == 0
val res = tree.get(x, y, z)
assert(res == c)
z++
}
y++
}
x++
}
}
@@ -0,0 +1,138 @@
open class OctoTree<T>(val depth: Int) {
private var root: Node<T>? = null
private var actual = false
//-------------------------------------------------------------------------//
fun get(x: Int, y: Int, z: Int): T? {
var dep = depth
var iter = root
while (true) {
if (iter == null) return null
else if (iter is Node.Leaf) return iter.value
iter = (iter as Node.Branch<T>).nodes[number(x, y, z, --dep)]
}
}
//-------------------------------------------------------------------------//
fun set(x: Int, y: Int, z: Int, value: T) {
if (root == null) root = Node.Branch()
if (root!!.set(x, y, z, value, depth - 1)) {
root = Node.Leaf(value)
}
actual = false
}
//-------------------------------------------------------------------------//
override fun toString(): String = root.toString()
//-------------------------------------------------------------------------//
sealed class Node<T> {
abstract fun set(x: Int, y: Int, z: Int, value: T, depth: Int): Boolean
//---------------------------------------------------------------------//
class Leaf<T>(var value: T) : Node<T>() {
override fun set(x: Int, y: Int, z: Int, value: T, depth: Int): Boolean {
throw UnsupportedOperationException("set on Leaf element")
}
override fun toString(): String = "L{$value}"
}
//---------------------------------------------------------------------//
class Branch<T>() : Node<T>() {
constructor(value: T, exclude: Int) : this() {
var i = 0
while (i < 8) {
if (i != exclude) {
nodes[i] = Leaf(value)
}
i++
}
}
private fun canClusterize(value: T): Boolean {
var i = 0
while (i < 8) {
val w = nodes[i]
if (w == null || w !is Leaf || value != w.value) {
return false
}
i++
}
return true
}
override fun set(x: Int, y: Int, z: Int, value: T, depth: Int): Boolean {
val branchIndex = number(x, y, z, depth)
val node = nodes[branchIndex]
when (node) {
null -> {
if (depth == 0) {
nodes[branchIndex] = Leaf(value)
return canClusterize(value)
} else {
nodes[branchIndex] = Branch()
}
}
is Leaf<T> -> {
if (node.value == value) {
return false
} else if (depth == 0) {
node.value = value
return canClusterize(value)
}
nodes[branchIndex] = Branch(node.value, number(x, y, z, depth - 1))
}
}
if (nodes[branchIndex]!!.set(x, y, z, value, depth - 1)) {
nodes[branchIndex] = Leaf(value)
return canClusterize(value)
}
return false
}
val nodes = arrayOfNulls<Node<T>>(8)
override fun toString(): String = nodes.joinToString(prefix = "[", postfix = "]")
}
}
//-------------------------------------------------------------------------//
companion object {
fun number(x: Int, y: Int, z: Int, depth: Int): Int {
val mask = 1 shl depth
if (x and mask != 0) {
if (y and mask != 0) {
if (z and mask != 0)
return 7
return 6
}
if (z and mask != 0)
return 5
return 4
}
if (y and mask != 0) {
if (z and mask != 0)
return 3
return 2
}
if (z and mask != 0)
return 1
return 0
}
}
}
@@ -0,0 +1,77 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
val OBJ = Any()
open class ParameterNotNullAssertionBenchmark {
fun methodWithOneNotnullParameter(p: Any): Any {
return p
}
private fun privateMethodWithOneNotnullParameter(p: Any): Any {
return p
}
fun methodWithTwoNotnullParameters(p: Any, p2: Any): Any {
return p
}
private fun privateMethodWithTwoNotnullParameters(p: Any, p2: Any): Any {
return p
}
fun methodWithEightNotnullParameters(p: Any, p2: Any, p3: Any, p4: Any, p5: Any, p6: Any, p7: Any, p8: Any): Any {
return p
}
private fun privateMethodWithEightNotnullParameters(p: Any, p2: Any, p3: Any, p4: Any, p5: Any, p6: Any, p7: Any, p8: Any): Any {
return p
}
//Benchmark
fun invokeOneArgWithNullCheck(): Any {
return methodWithOneNotnullParameter(OBJ)
}
//Benchmark
fun invokeOneArgWithoutNullCheck(): Any {
return privateMethodWithOneNotnullParameter(OBJ)
}
//Benchmark
fun invokeTwoArgsWithNullCheck(): Any {
return methodWithTwoNotnullParameters(OBJ, OBJ)
}
//Benchmark
fun invokeTwoArgsWithoutNullCheck(): Any {
return privateMethodWithTwoNotnullParameters(OBJ, OBJ)
}
//Benchmark
fun invokeEightArgsWithNullCheck(): Any {
return methodWithEightNotnullParameters(OBJ, OBJ, OBJ, OBJ, OBJ, OBJ, OBJ, OBJ)
}
//Benchmark
fun invokeEightArgsWithoutNullCheck(): Any {
return privateMethodWithEightNotnullParameters(OBJ, OBJ, OBJ, OBJ, OBJ, OBJ, OBJ, OBJ)
}
}
@@ -0,0 +1,60 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
/**
* This class tests linked list performance
* using prime number calculation algorithms
*
* @author Mikhail Glukhikh
*/
open class PrimeListBenchmark {
private var primes: MutableList<Int> = mutableListOf()
//Benchmark
fun calcDirect() {
primes.clear()
primes.add(2)
var i = 3
while (i <= BENCHMARK_SIZE) {
var simple = true
for (prime in primes) {
if (prime * prime > i)
break
if (i % prime == 0) {
simple = false
break
}
}
if (simple)
primes.add(i)
i += 2
}
}
//Benchmark
fun calcEratosthenes() {
primes.clear()
primes.addAll(2..BENCHMARK_SIZE)
var i = 0
while (i < primes.size) {
val divisor = primes[i]
primes.removeAll { it -> it > divisor && it % divisor == 0 }
i++
}
}
}
@@ -0,0 +1,27 @@
/*
* 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.ring
import org.jetbrains.benchmarksLauncher.Blackhole
import org.jetbrains.benchmarksLauncher.Random
private object A {
val a = Random.nextInt(100)
}
open class SingletonBenchmark {
init {
// Make sure A is initialized.
Blackhole.consume(A.a)
}
// Benchmark
fun access() {
for (i in 0 until BENCHMARK_SIZE) {
Blackhole.consume(A.a)
}
}
}
@@ -0,0 +1,78 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
import org.jetbrains.benchmarksLauncher.Random
open class StringBenchmark {
private var _data: ArrayList<String>? = null
val data: ArrayList<String>
get() = _data!!
var csv: String = ""
init {
val list = ArrayList<String>(BENCHMARK_SIZE)
for (n in stringValues(BENCHMARK_SIZE))
list.add(n)
_data = list
csv = ""
for (i in 1..BENCHMARK_SIZE-1) {
val elem = Random.nextDouble()
csv += elem
csv += ","
}
csv += 0.0
}
//Benchmark
open fun stringConcat(): String? {
var string: String = ""
for (it in data) string += it
return string
}
//Benchmark
open fun stringConcatNullable(): String? {
var string: String? = ""
for (it in data) string += it
return string
}
//Benchmark
open fun stringBuilderConcat(): String {
var string : StringBuilder = StringBuilder("")
for (it in data) string.append(it)
return string.toString()
}
//Benchmark
open fun stringBuilderConcatNullable(): String {
var string : StringBuilder? = StringBuilder("")
for (it in data) string?.append(it)
return string.toString()
}
//Benchmark
open fun summarizeSplittedCsv(): Double {
val fields = csv.split(",")
var sum = 0.0
for (field in fields) {
sum += field.toDouble()
}
return sum
}
}
@@ -0,0 +1,674 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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,
361, 487, 563, 617, 677,
751, 823, 883, 967, 1031)
const val V1 = 1
const val V2 = 2
const val V3 = 3
const val V4 = 4
const val V5 = 5
const val V6 = 6
const val V7 = 7
const val V8 = 8
const val V9 = 9
const val V10 = 10
const val V11 = 11
const val V12 = 12
const val V13 = 13
const val V14 = 14
const val V15 = 15
const val V16 = 16
const val V17 = 17
const val V18 = 18
const val V19 = 19
const val V20 = 20
object Numbers {
const val V1 = 1
const val V2 = 2
const val V3 = 3
const val V4 = 4
const val V5 = 5
const val V6 = 6
const val V7 = 7
const val V8 = 8
const val V9 = 9
const val V10 = 10
const val V11 = 11
const val V12 = 12
const val V13 = 13
const val V14 = 14
const val V15 = 15
const val V16 = 16
const val V17 = 17
const val V18 = 18
const val V19 = 19
const val V20 = 20
}
var VV1 = 1
var VV2 = 2
var VV3 = 3
var VV4 = 4
var VV5 = 5
var VV6 = 6
var VV7 = 7
var VV8 = 8
var VV9 = 9
var VV10 = 10
var VV11 = 11
var VV12 = 12
var VV13 = 13
var VV14 = 14
var VV15 = 15
var VV16 = 16
var VV17 = 17
var VV18 = 18
var VV19 = 19
var VV20 = 20
open class SwitchBenchmark {
fun sparseIntSwitch(u : Int) : Int {
var t : Int
when (u) {
11 -> {
t = 1
}
29 -> {
t = 2
}
47 -> {
t = 3
}
71 -> {
t = 4
}
103 -> {
t = 5
}
149 -> {
t = 6
}
175 -> {
t = 7
}
227 -> {
t = 1
}
263 -> {
t = 9
}
307 -> {
t = 1
}
361 -> {
t = 2
}
487 -> {
t = 3
}
563 -> {
t = 4
}
617 -> {
t = 4
}
677 -> {
t = 4
}
751 -> {
t = 435
}
823 -> {
t = 31
}
883 -> {
t = 1
}
967 -> {
t = 1
}
1031 -> {
t = 1
}
20 -> {
t = 1
}
else -> {
t = 5
}
}
return t
}
fun denseIntSwitch(u : Int) : Int {
var t : Int
when (u) {
1 -> {
t = 1
}
-1 -> {
t = 2
}
2 -> {
t = 3
}
3 -> {
t = 4
}
4 -> {
t = 5
}
5 -> {
t = 6
}
6 -> {
t = 7
}
7 -> {
t = 1
}
8 -> {
t = 9
}
9 -> {
t = 1
}
10 -> {
t = 2
}
11 -> {
t = 3
}
12 -> {
t = 4
}
13 -> {
t = 4
}
14 -> {
t = 4
}
15 -> {
t = 435
}
16 -> {
t = 31
}
17 -> {
t = 1
}
18 -> {
t = 1
}
19 -> {
t = 1
}
20 -> {
t = 1
}
else -> {
t = 5
}
}
return t
}
fun constSwitch(u : Int) : Int {
var t : Int
when (u) {
V1 -> {
t = 1
}
V2 -> {
t = 3
}
V3 -> {
t = 4
}
V4 -> {
t = 5
}
V5 -> {
t = 6
}
V6 -> {
t = 7
}
V7 -> {
t = 1
}
V8 -> {
t = 9
}
V9 -> {
t = 1
}
V10 -> {
t = 2
}
V11 -> {
t = 3
}
V12 -> {
t = 4
}
V13 -> {
t = 4
}
V14 -> {
t = 4
}
V15 -> {
t = 435
}
V16 -> {
t = 31
}
V17 -> {
t = 1
}
V18 -> {
t = 1
}
V19 -> {
t = 1
}
V20 -> {
t = 1
}
else -> {
t = 5
}
}
return t
}
fun objConstSwitch(u : Int) : Int {
var t : Int
when (u) {
Numbers.V1 -> {
t = 1
}
Numbers.V2 -> {
t = 3
}
Numbers.V3 -> {
t = 4
}
Numbers.V4 -> {
t = 5
}
Numbers.V5 -> {
t = 6
}
Numbers.V6 -> {
t = 7
}
Numbers.V7 -> {
t = 1
}
Numbers.V8 -> {
t = 9
}
Numbers.V9 -> {
t = 1
}
Numbers.V10 -> {
t = 2
}
Numbers.V11 -> {
t = 3
}
Numbers.V12 -> {
t = 4
}
Numbers.V13 -> {
t = 4
}
Numbers.V14 -> {
t = 4
}
Numbers.V15 -> {
t = 435
}
Numbers.V16 -> {
t = 31
}
Numbers.V17 -> {
t = 1
}
Numbers.V18 -> {
t = 1
}
Numbers.V19 -> {
t = 1
}
Numbers.V20 -> {
t = 1
}
else -> {
t = 5
}
}
return t
}
fun varSwitch(u : Int) : Int {
var t : Int
when (u) {
VV1 -> {
t = 1
}
VV2 -> {
t = 3
}
VV3 -> {
t = 4
}
VV4 -> {
t = 5
}
VV5 -> {
t = 6
}
VV6 -> {
t = 7
}
VV7 -> {
t = 1
}
VV8 -> {
t = 9
}
VV9 -> {
t = 1
}
VV10 -> {
t = 2
}
VV11 -> {
t = 3
}
VV12 -> {
t = 4
}
VV13 -> {
t = 4
}
VV14 -> {
t = 4
}
VV15 -> {
t = 435
}
VV16 -> {
t = 31
}
VV17 -> {
t = 1
}
VV18 -> {
t = 1
}
VV19 -> {
t = 1
}
VV20 -> {
t = 1
}
else -> {
t = 5
}
}
return t
}
private fun stringSwitch(s: String) : Int {
when(s) {
"ABCDEFG1" -> return 1
"ABCDEFG2" -> return 2
"ABCDEFG2" -> return 3
"ABCDEFG3" -> return 4
"ABCDEFG4" -> return 5
"ABCDEFG5" -> return 6
"ABCDEFG6" -> return 7
"ABCDEFG7" -> return 8
"ABCDEFG8" -> return 9
"ABCDEFG9" -> return 10
"ABCDEFG10" -> return 11
"ABCDEFG11" -> return 12
"ABCDEFG12" -> return 1
"ABCDEFG13" -> return 2
"ABCDEFG14" -> return 3
"ABCDEFG15" -> return 4
"ABCDEFG16" -> return 5
"ABCDEFG17" -> return 6
"ABCDEFG18" -> return 7
"ABCDEFG19" -> return 8
"ABCDEFG20" -> return 9
else -> return -1
}
}
lateinit var denseIntData: IntArray
lateinit var sparseIntData: IntArray
//Benchmark
fun testSparseIntSwitch() {
for (i in sparseIntData) {
Blackhole.consume(sparseIntSwitch(i))
}
}
//Benchmark
fun testDenseIntSwitch() {
for (i in denseIntData) {
Blackhole.consume(denseIntSwitch(i))
}
}
//Benchmark
fun testConstSwitch() {
for (i in denseIntData) {
Blackhole.consume(constSwitch(i))
}
}
//Benchmark
fun testObjConstSwitch() {
for (i in denseIntData) {
Blackhole.consume(objConstSwitch(i))
}
}
//Benchmark
fun testVarSwitch() {
for (i in denseIntData) {
Blackhole.consume(varSwitch(i))
}
}
var data : Array<String> = arrayOf()
//Benchmark
fun testStringsSwitch() {
val n = data.size
for (s in data) {
Blackhole.consume(stringSwitch(s))
}
}
enum class MyEnum {
ITEM1, ITEM2, ITEM3, ITEM4, ITEM5, ITEM6, ITEM7, ITEM8, ITEM9, ITEM10, ITEM11, ITEM12, ITEM13, ITEM14, ITEM15, ITEM16, ITEM17, ITEM18, ITEM19, ITEM20, ITEM21, ITEM22, ITEM23, ITEM24, ITEM25, ITEM26, ITEM27, ITEM28, ITEM29, ITEM30, ITEM31, ITEM32, ITEM33, ITEM34, ITEM35, ITEM36, ITEM37, ITEM38, ITEM39, ITEM40, ITEM41, ITEM42, ITEM43, ITEM44, ITEM45, ITEM46, ITEM47, ITEM48, ITEM49, ITEM50, ITEM51, ITEM52, ITEM53, ITEM54, ITEM55, ITEM56, ITEM57, ITEM58, ITEM59, ITEM60, ITEM61, ITEM62, ITEM63, ITEM64, ITEM65, ITEM66, ITEM67, ITEM68, ITEM69, ITEM70, ITEM71, ITEM72, ITEM73, ITEM74, ITEM75, ITEM76, ITEM77, ITEM78, ITEM79, ITEM80, ITEM81, ITEM82, ITEM83, ITEM84, ITEM85, ITEM86, ITEM87, ITEM88, ITEM89, ITEM90, ITEM91, ITEM92, ITEM93, ITEM94, ITEM95, ITEM96, ITEM97, ITEM98, ITEM99, ITEM100
}
private fun enumSwitch(x: MyEnum) : Int {
when (x) {
MyEnum.ITEM5 -> return 1
MyEnum.ITEM10 -> return 2
MyEnum.ITEM15 -> return 3
MyEnum.ITEM20 -> return 4
MyEnum.ITEM25 -> return 5
MyEnum.ITEM30 -> return 6
MyEnum.ITEM35 -> return 7
MyEnum.ITEM40 -> return 8
MyEnum.ITEM45 -> return 9
MyEnum.ITEM50 -> return 10
MyEnum.ITEM55 -> return 11
MyEnum.ITEM60 -> return 12
MyEnum.ITEM65 -> return 13
MyEnum.ITEM70 -> return 14
MyEnum.ITEM75 -> return 15
MyEnum.ITEM80 -> return 16
MyEnum.ITEM85 -> return 17
MyEnum.ITEM90 -> return 18
MyEnum.ITEM95 -> return 19
MyEnum.ITEM100 -> return 20
else -> return -1
}
}
private fun denseEnumSwitch(x: MyEnum) : Int {
when (x) {
MyEnum.ITEM1 -> return 1
MyEnum.ITEM2 -> return 2
MyEnum.ITEM3 -> return 3
MyEnum.ITEM4 -> return 4
MyEnum.ITEM5 -> return 5
MyEnum.ITEM6 -> return 6
MyEnum.ITEM7 -> return 7
MyEnum.ITEM8 -> return 8
MyEnum.ITEM9 -> return 9
MyEnum.ITEM10 -> return 10
MyEnum.ITEM11 -> return 11
MyEnum.ITEM12 -> return 12
MyEnum.ITEM13 -> return 13
MyEnum.ITEM14 -> return 14
MyEnum.ITEM15 -> return 15
MyEnum.ITEM16 -> return 16
MyEnum.ITEM17 -> return 17
MyEnum.ITEM18 -> return 18
MyEnum.ITEM19 -> return 19
MyEnum.ITEM20 -> return 20
else -> return -1
}
}
lateinit var enumData : Array<MyEnum>
lateinit var denseEnumData : Array<MyEnum>
//Benchmark
fun testEnumsSwitch() {
val n = enumData.size -1
val data = enumData
for (i in 0..n) {
Blackhole.consume(enumSwitch(data[i]))
}
}
//Benchmark
fun testDenseEnumsSwitch() {
val n = denseEnumData.size -1
val data = denseEnumData
for (i in 0..n) {
Blackhole.consume(denseEnumSwitch(data[i]))
}
}
sealed class MySealedClass {
class MySealedClass1: MySealedClass()
class MySealedClass2: MySealedClass()
class MySealedClass3: MySealedClass()
class MySealedClass4: MySealedClass()
class MySealedClass5: MySealedClass()
class MySealedClass6: MySealedClass()
class MySealedClass7: MySealedClass()
class MySealedClass8: MySealedClass()
class MySealedClass9: MySealedClass()
class MySealedClass10: MySealedClass()
}
lateinit var sealedClassData: Array<MySealedClass>
init {
data = Array(BENCHMARK_SIZE) {
"ABCDEFG" + Random.nextInt(22)
}
enumData = Array(BENCHMARK_SIZE) {
MyEnum.values()[it % MyEnum.values().size]
}
denseEnumData = Array(BENCHMARK_SIZE) {
MyEnum.values()[it % 20]
}
denseIntData = IntArray(BENCHMARK_SIZE) { Random.nextInt(25) - 1 }
sparseIntData = IntArray(BENCHMARK_SIZE) { SPARSE_SWITCH_CASES[Random.nextInt(20)] }
sealedClassData = Array(BENCHMARK_SIZE) {
when(Random.nextInt(10)) {
0 -> MySealedClass.MySealedClass1()
1 -> MySealedClass.MySealedClass2()
2 -> MySealedClass.MySealedClass3()
3 -> MySealedClass.MySealedClass4()
4 -> MySealedClass.MySealedClass5()
5 -> MySealedClass.MySealedClass6()
6 -> MySealedClass.MySealedClass7()
7 -> MySealedClass.MySealedClass8()
8 -> MySealedClass.MySealedClass9()
9 -> MySealedClass.MySealedClass10()
else -> throw IllegalStateException()
}
}
}
private fun sealedWhenSwitch(x: MySealedClass) : Int =
when (x) {
is MySealedClass.MySealedClass1 -> 1
is MySealedClass.MySealedClass2 -> 2
is MySealedClass.MySealedClass3 -> 3
is MySealedClass.MySealedClass4 -> 4
is MySealedClass.MySealedClass5 -> 5
is MySealedClass.MySealedClass6 -> 6
is MySealedClass.MySealedClass7 -> 7
is MySealedClass.MySealedClass8 -> 8
is MySealedClass.MySealedClass9 -> 9
is MySealedClass.MySealedClass10 -> 10
}
//Benchmark
fun testSealedWhenSwitch() {
val n = sealedClassData.size -1
for (i in 0..n) {
Blackhole.consume(sealedWhenSwitch(sealedClassData[i]))
}
}
}
@@ -0,0 +1,43 @@
/*
* Copyright 2010-2018 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
const val BENCHMARK_SIZE = 10000
expect class AtomicRef<T> {
/**
* Reading/writing this property maps to read/write of volatile variable.
*/
public var value: T
/**
* Maps to [AtomicReferenceFieldUpdater.lazySet].
*/
public fun lazySet(value: T)
/**
* Maps to [AtomicReferenceFieldUpdater.compareAndSet].
*/
public fun compareAndSet(expect: T, update: T): Boolean
/**
* Maps to [AtomicReferenceFieldUpdater.getAndSet].
*/
public fun getAndSet(value: T): T
}
public expect fun <T> atomic(initial: T): AtomicRef<T>
@@ -0,0 +1,54 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
import org.jetbrains.benchmarksLauncher.Blackhole
open class WithIndiciesBenchmark {
private var _data: ArrayList<Value>? = null
val data: ArrayList<Value>
get() = _data!!
init {
val list = ArrayList<Value>(BENCHMARK_SIZE)
for (n in classValues(BENCHMARK_SIZE))
list.add(n)
_data = list
}
//Benchmark
fun withIndicies() {
for ((index, value) in data.withIndex()) {
if (filterLoad(value)) {
Blackhole.consume(index)
Blackhole.consume(value)
}
}
}
//Benchmark
fun withIndiciesManual() {
var index = 0
for (value in data) {
if (filterLoad(value)) {
Blackhole.consume(index)
Blackhole.consume(value)
}
index++
}
}
}
@@ -0,0 +1,520 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.ring
val zdf_win = listOf(
"-де",
"-ка",
"-либо",
"-нибудь",
"-с",
"-таки",
"-то",
"а",
"а-конто",
"а-ля",
"аба",
"абажур",
"абажурный",
"абаз",
"абазин",
"абазинец",
"абазинка",
"абазинский",
"абак",
"абака",
"аббат",
"аббатиса",
"аббатский",
"аббатство",
"аббревиатура",
"аббревиатурный",
"аббревиация",
"абдикация",
"абдомен",
"абдоминальный",
"абдуктор",
"абдукторный",
"абдукция",
"абелит",
"аберрационный",
"аберрация",
"абзац",
"абзацный",
"абиетин",
"абиетиновый",
"абиссальный",
"абиссинец",
"абиссинский",
"абитуриент",
"абитуриентка",
"абитуриентский",
"аблактировать",
"аблактировка",
"аблятив",
"абляут",
"абляция",
"аболиционизм",
"аболиционист",
"аболиционистский",
"аболиция",
"абонемент",
"абонементный",
"абонент",
"абонентка",
"абонентный",
"абонентский",
"абонирование",
"абонировать",
"абонироваться",
"абордаж",
"абордажный",
"абордировать",
"абориген",
"аборигенный",
"аборт",
"абортарий",
"абортивный",
"абортировать",
"абразив",
"абразивный",
"абразионный",
"абразия",
"абракадабра",
"абреже",
"абрек",
"абрикос",
"абрикосный",
"абрикосовка",
"абрикосовый",
"абрикотин",
"абрис",
"абрисный",
"абсент",
"абсентеизм",
"абсентеист",
"абсолют",
"абсолютивный",
"абсолютизирование",
"абсолютизировать",
"абсолютизм",
"абсолютист",
"абсолютистский",
"абсолютность",
"абсолютный",
"абсолюция",
"абсорбент",
"абсорбер",
"абсорбировать",
"абсорбционный",
"абсорбция",
"абстинент",
"абстрагирование",
"абстрагировать",
"абстрагироваться",
"абстракт",
"абстрактность",
"абстрактный",
"абстракционизм",
"абстракционист",
"абстракционистский",
"абстракция",
"абсурд",
"абсурдность",
"абсурдный",
"абсцесс",
"абсцисса",
"абулия",
"абхаз",
"абхазец",
"абхазка",
"абхазский",
"абцуг",
"абштрих",
"абъюрация",
"абы",
"авалист",
"аваль",
"авангард",
"авангардизм",
"авангардист",
"авангардистский",
"авангардный",
"аванзал",
"аванзальный",
"аванкамера",
"аванложа",
"аванпорт",
"аванпост",
"аванпостный",
"аванс",
"авансирование",
"авансировать",
"авансовый",
"авансом",
"авансцена",
"авантаж",
"авантажный",
"авантюра",
"авантюризм",
"авантюрин",
"авантюриновый",
"авантюрист",
"авантюристический",
"авантюристичный",
"авантюристка",
"авантюристский",
"авантюрность",
"авантюрный",
"авар",
"аварец",
"аварийность",
"аварийный",
"аварийщик",
"авария",
"аварка",
"аварский",
"авгиев",
"авгит",
"авгур",
"август",
"августейший",
"августинец",
"августовский",
"авдотка",
"авеню",
"аверс",
"авестийский",
"авиабаза",
"авиабензин",
"авиагоризонт",
"авиадвигатель",
"авиадесант",
"авиадесантный",
"авиазавод",
"авиаконструктор",
"авиалиния",
"авиаматка",
"авиамоделизм",
"авиамоделист",
"авиамодель",
"авиамодельный",
"авиамотор",
"авиамоторный",
"авианосец",
"авиапочта",
"авиаприбор",
"авиапромышленность",
"авиапромышленный",
"авиаразведка",
"авиастроение",
"авиастроитель",
"авиастроительный",
"авиастроительство",
"авиасъёмка",
"авиатехник",
"авиатор",
"авиаторский",
"авиатранспорт",
"авиатранспортный",
"авиатрасса",
"авиационный",
"авиация",
"авиачасть",
"авиашкола",
"авиетка",
"авизировать",
"авизный",
"авизо",
"авитаминоз",
"авитаминозный",
"авифауна",
"авокадо",
"авось",
"авоська",
"аврал",
"авралить",
"авральный",
"авран",
"аврора",
"австралиец",
"австралийка",
"австралийский",
"австралопитек",
"австриец",
"австрийка",
"австрийский",
"австрияк",
"австриячка",
"австро-венгерский",
"автаркический",
"автаркия",
"авто",
"автобаза",
"автобиографический",
"автобиографичность",
"автобиографичный",
"автобиография",
"автоблокировка",
"автоблокировочный",
"автобус",
"автобусник",
"автобусный",
"автовакцина",
"автовесы",
"автовокзал",
"автогамия",
"автоген",
"автогенез",
"автогенератор",
"автогенный",
"автогенщик",
"автогипноз",
"автогонки",
"автогравюра",
"автограф",
"автографический",
"автография",
"автогужевой",
"автодидакт",
"автодоение",
"автодорожник",
"автодорожный",
"автодрезина",
"автодром",
"автожир",
"автозавод",
"автозаводец",
"автозаводский",
"автозаводской",
"автозаправочный",
"автозаправщик",
"автоинспектор",
"автоинспекция",
"автокар",
"автокара",
"автокатализ",
"автокефалия",
"автокефальный",
"автоклав",
"автоклуб",
"автоколонна",
"автокомбинат",
"автокран",
"автократ",
"автократический",
"автократия",
"автокружок",
"автол",
"автолавка",
"автолиз",
"автолитография",
"автолюбитель",
"автолюбительство",
"автомагистраль",
"автомат",
"автоматизация",
"автоматизирование",
"автоматизировать",
"автоматизироваться",
"автоматизм",
"автоматика",
"автоматический",
"автоматичность",
"автоматичный",
"автоматный",
"автоматчик",
"автоматчица",
"автомашина",
"автомашинист",
"автомеханик",
"автомобилестроение",
"автомобилестроитель",
"автомобилестроительный",
"автомобилизация",
"автомобилизм",
"автомобилист",
"автомобилистка",
"автомобиль",
"автомобильный",
"автомобильчик",
"автоморфизм",
"автомотоклуб",
"автомоторный",
"автомотошкола",
"автомотриса",
"автономист",
"автономистский",
"автономический",
"автономия",
"автономность",
"автономный",
"автопарк",
"автоперевозка",
"автопилот",
"автопластика",
"автоплуг",
"автопогрузчик",
"автоподъёмник",
"автопоезд",
"автопоилка",
"автопокрышка",
"автопортрет",
"автопробег",
"автопромышленность",
"автор",
"авторалли",
"авторегулятор",
"авторемонтник",
"авторемонтный",
"автореферат",
"авторефрижератор",
"авторизация",
"авторизованный",
"авторизовать",
"авторитарность",
"авторитарный",
"авторитет",
"авторитетность",
"авторитетный",
"авторота",
"авторские",
"авторский",
"авторство",
"авторулевой",
"авторучка",
"автосани",
"автосборка",
"автосварщик",
"автоспорт",
"автостанция",
"автостоп",
"автострада",
"автостроение",
"автостроитель",
"автосцепка",
"автотележка",
"автотип",
"автотипический",
"автотипия",
"автотипный",
"автотомия",
"автотормоз",
"автотормозной",
"автотракторный",
"автотранспорт",
"автотранспортный",
"автотрансформатор",
"автотрасса",
"автотуризм",
"автотурист",
"автоукладчик",
"автофургон",
"автохозяйство",
"автохром",
"автохромный",
"автохтон",
"автохтонный",
"автоцистерна",
"авточасть",
"автошкола",
"автоштурман",
"авуары",
"ага",
"ага-хан",
"агава",
"агалит",
"агальматолит",
"агама",
"агами",
"агамия",
"агамогония",
"агар-агар",
"агарный",
"агаровый",
"агарянин",
"агат",
"агатный",
"агатовый",
"агглютинативность",
"агглютинативный",
"агглютинация",
"агглютинин",
"агглютинирующий",
"аггравация",
"агент",
"агентский",
"агентство",
"агентура",
"агентурный",
"агиографический",
"агиография",
"агиология",
"агитатор",
"агитаторский",
"агитаторша",
"агитационный",
"агитация",
"агитбригада",
"агитировать",
"агитка",
"агиткампания",
"агитмассовый",
"агитпоезд",
"агитпроп",
"агитпункт",
"аглицкий",
"агломерат",
"агломератчик",
"агломерационный",
"агломерация",
"агломерировать",
"агломерироваться",
"агнат",
"агнец",
"агнозия",
"агностик",
"агностицизм",
"агностический",
"агонизировать",
"агонический",
"агония",
"агорафобия",
"аграмант",
"аграмантовый",
"аграрий",
"аграрник",
"аграрный",
"аграф",
"аграфия",
"агрегат",
"агрегатный",
"агреман",
"агрессивность",
"агрессивный",
"агрессия",
"агрессор",
"агрикультура",
"агрикультурный",
"агробаза",
"агробиолог",
"агробиологический",
"агробиология",
"агроботаника",
"агрозоотехника",
"агромелиорация"
)