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:
@@ -0,0 +1,58 @@
|
||||
buildscript {
|
||||
apply from: "$rootProject.projectDir/gradle/kotlinGradlePlugin.gradle"
|
||||
repositories {
|
||||
maven {
|
||||
url 'https://cache-redirector.jetbrains.com/jcenter'
|
||||
}
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
def rootBuildDirectory = rootProject.projectDir
|
||||
|
||||
task konanRun {
|
||||
subprojects.each {
|
||||
dependsOn it.getTasksByName('konanRun', true)[0]
|
||||
}
|
||||
}
|
||||
|
||||
task jvmRun {
|
||||
subprojects.each {
|
||||
dependsOn it.getTasksByName('jvmRun', true)[0]
|
||||
}
|
||||
}
|
||||
|
||||
task clean {
|
||||
subprojects.each {
|
||||
dependsOn it.getTasksByName('clean', true)[0]
|
||||
}
|
||||
doLast {
|
||||
delete "${buildDir.absolutePath}"
|
||||
}
|
||||
}
|
||||
|
||||
defaultTasks 'konanRun'
|
||||
|
||||
task mergeNativeReports {
|
||||
doLast {
|
||||
mergeReports(nativeJson)
|
||||
uploadBenchmarkResultToArtifactory(nativeJson)
|
||||
}
|
||||
}
|
||||
|
||||
task mergeJvmReports {
|
||||
doLast {
|
||||
mergeReports(jvmJson)
|
||||
uploadBenchmarkResultToArtifactory(jvmJson)
|
||||
}
|
||||
}
|
||||
|
||||
subprojects.each {
|
||||
it.getTasksByName('jvmJsonReport', true)[0].finalizedBy mergeJvmReports
|
||||
it.getTasksByName('konanJsonReport', true)[0].finalizedBy mergeNativeReports
|
||||
}
|
||||
|
||||
task ring {
|
||||
dependsOn 'clean'
|
||||
dependsOn 'ring:konanRun'
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import org.jetbrains.kotlin.benchmark.CodeSizeEntity
|
||||
|
||||
plugins {
|
||||
id("swift-benchmarking")
|
||||
}
|
||||
|
||||
val toolsPath = "../../../tools"
|
||||
|
||||
swiftBenchmark {
|
||||
applicationName = "Ring"
|
||||
commonSrcDirs = listOf("$toolsPath/benchmarks/shared/src/main/kotlin", "../../shared/src/main/kotlin")
|
||||
nativeSrcDirs = listOf("../../shared/src/main/kotlin-native/common", "../../shared/src/main/kotlin-native/posix")
|
||||
swiftSources = File("$projectDir/src").list().map { "$projectDir/src/$it" }.toList()
|
||||
compileTasks = listOf("buildSwift")
|
||||
useCodeSize = CodeSizeEntity.EXECUTABLE
|
||||
dependencies.common(project(":endorsedLibraries:kotlinx.cli"))
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
kotlin.native.home=../../../dist
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class AbstractMethodBenchmark {
|
||||
private let arr: [String] = zdf_win
|
||||
private let sequence = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"
|
||||
|
||||
private var sequenceMap: [Character: Int] = [:]
|
||||
|
||||
init() {
|
||||
var i = 0
|
||||
for ch in sequence {
|
||||
sequenceMap[ch] = i
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
|
||||
func sortStrings() -> Set<String> {
|
||||
var size = arr.count
|
||||
if (Constants.BENCHMARK_SIZE < size) {
|
||||
size = Constants.BENCHMARK_SIZE
|
||||
}
|
||||
let res = Set(arr[0..<size])
|
||||
return res
|
||||
}
|
||||
|
||||
func sortStringsWithComparator() -> Set<String> {
|
||||
var res = Set<String>()
|
||||
var size = Constants.BENCHMARK_SIZE < arr.count ? Constants.BENCHMARK_SIZE : arr.count
|
||||
arr[0..<size].forEach { (member) in
|
||||
res.insert(member)
|
||||
}
|
||||
return res
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,477 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol I {
|
||||
func foo() -> Int
|
||||
}
|
||||
|
||||
protocol E {
|
||||
func foo() -> Any
|
||||
}
|
||||
|
||||
extension I {
|
||||
func foo1() -> Int {
|
||||
return 1
|
||||
}
|
||||
func foo2() -> Int {
|
||||
return 2
|
||||
}
|
||||
func foo3() -> Int {
|
||||
return 3
|
||||
}
|
||||
func foo4() -> Int {
|
||||
return 4
|
||||
}
|
||||
func foo5() -> Int {
|
||||
return 5
|
||||
}
|
||||
func foo6() -> Int {
|
||||
return 6
|
||||
}
|
||||
func foo7() -> Int {
|
||||
return 7
|
||||
}
|
||||
func foo8() -> Int {
|
||||
return 8
|
||||
}
|
||||
func foo9() -> Int {
|
||||
return 9
|
||||
}
|
||||
func foo10() -> Int {
|
||||
return 10
|
||||
}
|
||||
func foo11() -> Int {
|
||||
return 11
|
||||
}
|
||||
func foo12() -> Int {
|
||||
return 12
|
||||
}
|
||||
func foo13() -> Int {
|
||||
return 13
|
||||
}
|
||||
func foo14() -> Int {
|
||||
return 14
|
||||
}
|
||||
func foo15() -> Int {
|
||||
return 15
|
||||
}
|
||||
func foo16() -> Int {
|
||||
return 16
|
||||
}
|
||||
func foo17() -> Int {
|
||||
return 17
|
||||
}
|
||||
func foo18() -> Int {
|
||||
return 18
|
||||
}
|
||||
func foo19() -> Int {
|
||||
return 19
|
||||
}
|
||||
func foo20() -> Int {
|
||||
return 20
|
||||
}
|
||||
func foo21() -> Int {
|
||||
return 21
|
||||
}
|
||||
func foo22() -> Int {
|
||||
return 22
|
||||
}
|
||||
func foo23() -> Int {
|
||||
return 23
|
||||
}
|
||||
func foo24() -> Int {
|
||||
return 24
|
||||
}
|
||||
func foo25() -> Int {
|
||||
return 25
|
||||
}
|
||||
func foo26() -> Int {
|
||||
return 26
|
||||
}
|
||||
func foo27() -> Int {
|
||||
return 27
|
||||
}
|
||||
func foo28() -> Int {
|
||||
return 28
|
||||
}
|
||||
func foo29() -> Int {
|
||||
return 29
|
||||
}
|
||||
func foo30() -> Int {
|
||||
return 30
|
||||
}
|
||||
func foo31() -> Int {
|
||||
return 31
|
||||
}
|
||||
func foo32() -> Int {
|
||||
return 32
|
||||
}
|
||||
func foo33() -> Int {
|
||||
return 33
|
||||
}
|
||||
func foo34() -> Int {
|
||||
return 34
|
||||
}
|
||||
func foo35() -> Int {
|
||||
return 35
|
||||
}
|
||||
func foo36() -> Int {
|
||||
return 36
|
||||
}
|
||||
func foo37() -> Int {
|
||||
return 37
|
||||
}
|
||||
func foo38() -> Int {
|
||||
return 38
|
||||
}
|
||||
func foo39() -> Int {
|
||||
return 39
|
||||
}
|
||||
func foo40() -> Int {
|
||||
return 40
|
||||
}
|
||||
func foo41() -> Int {
|
||||
return 41
|
||||
}
|
||||
func foo42() -> Int {
|
||||
return 42
|
||||
}
|
||||
func foo43() -> Int {
|
||||
return 43
|
||||
}
|
||||
func foo44() -> Int {
|
||||
return 44
|
||||
}
|
||||
func foo45() -> Int {
|
||||
return 45
|
||||
}
|
||||
func foo46() -> Int {
|
||||
return 46
|
||||
}
|
||||
func foo47() -> Int {
|
||||
return 47
|
||||
}
|
||||
func foo48() -> Int {
|
||||
return 48
|
||||
}
|
||||
func foo49() -> Int {
|
||||
return 49
|
||||
}
|
||||
func foo50() -> Int {
|
||||
return 50
|
||||
}
|
||||
func foo51() -> Int {
|
||||
return 51
|
||||
}
|
||||
func foo52() -> Int {
|
||||
return 52
|
||||
}
|
||||
func foo53() -> Int {
|
||||
return 53
|
||||
}
|
||||
func foo54() -> Int {
|
||||
return 54
|
||||
}
|
||||
func foo55() -> Int {
|
||||
return 55
|
||||
}
|
||||
func foo56() -> Int {
|
||||
return 56
|
||||
}
|
||||
func foo57() -> Int {
|
||||
return 57
|
||||
}
|
||||
func foo58() -> Int {
|
||||
return 58
|
||||
}
|
||||
func foo59() -> Int {
|
||||
return 59
|
||||
}
|
||||
func foo60() -> Int {
|
||||
return 60
|
||||
}
|
||||
func foo61() -> Int {
|
||||
return 31
|
||||
}
|
||||
func foo62() -> Int {
|
||||
return 62
|
||||
}
|
||||
func foo63() -> Int {
|
||||
return 63
|
||||
}
|
||||
func foo64() -> Int {
|
||||
return 64
|
||||
}
|
||||
func foo65() -> Int {
|
||||
return 65
|
||||
}
|
||||
func foo66() -> Int {
|
||||
return 66
|
||||
}
|
||||
func foo67() -> Int {
|
||||
return 67
|
||||
}
|
||||
func foo68() -> Int {
|
||||
return 68
|
||||
}
|
||||
func foo69() -> Int {
|
||||
return 69
|
||||
}
|
||||
func foo70() -> Int {
|
||||
return 70
|
||||
}
|
||||
func foo71() -> Int {
|
||||
return 71
|
||||
}
|
||||
func foo72() -> Int {
|
||||
return 72
|
||||
}
|
||||
func foo73() -> Int {
|
||||
return 73
|
||||
}
|
||||
func foo74() -> Int {
|
||||
return 74
|
||||
}
|
||||
func foo75() -> Int {
|
||||
return 75
|
||||
}
|
||||
func foo76() -> Int {
|
||||
return 76
|
||||
}
|
||||
func foo77() -> Int {
|
||||
return 77
|
||||
}
|
||||
func foo78() -> Int {
|
||||
return 78
|
||||
}
|
||||
func foo79() -> Int {
|
||||
return 79
|
||||
}
|
||||
func foo80() -> Int {
|
||||
return 80
|
||||
}
|
||||
func foo81() -> Int {
|
||||
return 81
|
||||
}
|
||||
func foo82() -> Int {
|
||||
return 82
|
||||
}
|
||||
func foo83() -> Int {
|
||||
return 83
|
||||
}
|
||||
func foo84() -> Int {
|
||||
return 84
|
||||
}
|
||||
func foo85() -> Int {
|
||||
return 85
|
||||
}
|
||||
func foo86() -> Int {
|
||||
return 86
|
||||
}
|
||||
func foo87() -> Int {
|
||||
return 87
|
||||
}
|
||||
func foo88() -> Int {
|
||||
return 88
|
||||
}
|
||||
func foo89() -> Int {
|
||||
return 89
|
||||
}
|
||||
func foo90() -> Int {
|
||||
return 90
|
||||
}
|
||||
func foo91() -> Int {
|
||||
return 91
|
||||
}
|
||||
func foo92() -> Int {
|
||||
return 92
|
||||
}
|
||||
func foo93() -> Int {
|
||||
return 93
|
||||
}
|
||||
func foo94() -> Int {
|
||||
return 94
|
||||
}
|
||||
func foo95() -> Int {
|
||||
return 95
|
||||
}
|
||||
func foo96() -> Int {
|
||||
return 96
|
||||
}
|
||||
func foo97() -> Int {
|
||||
return 97
|
||||
}
|
||||
func foo98() -> Int {
|
||||
return 98
|
||||
}
|
||||
func foo99() -> Int {
|
||||
return 99
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protocol A : I {}
|
||||
|
||||
class CallsBenchmarks {
|
||||
class B : A {
|
||||
func foo() -> Int {
|
||||
return 42
|
||||
}
|
||||
}
|
||||
class C : A {
|
||||
func foo() -> Int {
|
||||
return 117
|
||||
}
|
||||
}
|
||||
class D : A {
|
||||
func foo() -> Int {
|
||||
return 314
|
||||
}
|
||||
}
|
||||
class X : A {
|
||||
func foo() -> Int {
|
||||
return 456456
|
||||
}
|
||||
}
|
||||
class Y : A {
|
||||
func foo() -> Int {
|
||||
return -398473
|
||||
}
|
||||
}
|
||||
class Z : A {
|
||||
func foo() -> Int {
|
||||
return 8298734
|
||||
}
|
||||
}
|
||||
|
||||
let d = D()
|
||||
let a1: A = B()
|
||||
let a2: A = C()
|
||||
lazy var a3: A = d
|
||||
lazy var i1: I = a1
|
||||
lazy var i2: I = a2
|
||||
lazy var i3: I = d
|
||||
let i4: I = X()
|
||||
let i5: I = Y()
|
||||
let i6: I = Z()
|
||||
|
||||
func finalMethodCall() -> Int {
|
||||
var x = 0
|
||||
let d = self.d
|
||||
for _ in 0..<Constants.RUNS {
|
||||
x += d.foo()
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func classOpenMethodCall_MonomorphicCallsite() -> Int {
|
||||
var x = 0
|
||||
let a1 = self.a1
|
||||
for _ in 0..<Constants.RUNS {
|
||||
x += a1.foo()
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func classOpenMethodCall_BimorphicCallsite() -> Int {
|
||||
var x = 0
|
||||
let a1 = self.a1
|
||||
let a2 = self.a2
|
||||
for i in 0..<Constants.RUNS {
|
||||
x += ((i & 1 == 0) ? a1 : a2).foo()
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func classOpenMethodCall_TrimorphicCallsite() -> Int {
|
||||
var x = 0
|
||||
|
||||
let a1 = self.a1
|
||||
let a2 = self.a2
|
||||
let a3 = self.a3
|
||||
for i in 0..<Constants.RUNS {
|
||||
switch (i % 3) {
|
||||
case 1: x += a1.foo()
|
||||
case 2: x += a2.foo()
|
||||
default: x += a3.foo()
|
||||
}
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func interfaceMethodCall_MonomorphicCallsite() -> Int {
|
||||
var x = 0
|
||||
let i1 = self.i1
|
||||
for _ in 0..<Constants.RUNS {
|
||||
x += i1.foo()
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func interfaceMethodCall_BimorphicCallsite() -> Int {
|
||||
var x = 0
|
||||
let i1 = self.i1
|
||||
let i2 = self.i2
|
||||
for i in 0..<Constants.RUNS {
|
||||
x += ((i & 1 == 0) ? i1 : i2).foo()
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func interfaceMethodCall_TrimorphicCallsite() -> Int {
|
||||
var x = 0
|
||||
let i1 = self.i1
|
||||
let i2 = self.i2
|
||||
let i3 = self.i3
|
||||
for i in 0..<Constants.RUNS {
|
||||
switch (i % 3) {
|
||||
case 1: x += i1.foo()
|
||||
case 2: x += i2.foo()
|
||||
default: x += i3.foo()
|
||||
}
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func interfaceMethodCall_HexamorphicCallsite() -> Int {
|
||||
var x = 0
|
||||
let i1 = self.i1
|
||||
let i2 = self.i2
|
||||
let i3 = self.i3
|
||||
let i4 = self.i4
|
||||
let i5 = self.i5
|
||||
let i6 = self.i6
|
||||
for i in 0..<Constants.RUNS {
|
||||
switch (i % 6) {
|
||||
case 1: x += i1.foo()
|
||||
case 2: x += i2.foo()
|
||||
case 3: x += i3.foo()
|
||||
case 4: x += i4.foo()
|
||||
case 5: x += i5.foo()
|
||||
default: x += i6.foo()
|
||||
}
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
class F : E {
|
||||
func foo() -> Any {
|
||||
return 42
|
||||
}
|
||||
}
|
||||
|
||||
let e: E = F()
|
||||
|
||||
func returnBoxUnboxFolding() -> Int {
|
||||
var x = 0
|
||||
let e = self.e
|
||||
for _ in 0..<Constants.RUNS {
|
||||
x += e.foo() as! Int
|
||||
}
|
||||
return x
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
struct RunsInfo {
|
||||
static let RUNS = 2_000_000
|
||||
}
|
||||
|
||||
protocol I0 {}
|
||||
protocol I1 {}
|
||||
protocol I2: I0 {}
|
||||
protocol I3: I1 {}
|
||||
protocol I4: I0, I2 {}
|
||||
protocol I5: I3 {}
|
||||
protocol I6: I0, I2, I4 {}
|
||||
protocol I9: I0, I2, I4 {}
|
||||
protocol I7: I1 {}
|
||||
protocol I8: I0, I1 {}
|
||||
|
||||
class CastsBenchmark {
|
||||
class C0: I0 {}
|
||||
class C1: C0, I1 {}
|
||||
class C2: C1, I2 {}
|
||||
class C3: C2, I3 {}
|
||||
class C4: C3, I4 {}
|
||||
class C5: C4, I5 {}
|
||||
class C6: C5, I6 {}
|
||||
class C9: C5, I9 {}
|
||||
class C7: C3, I7 {}
|
||||
class C8: C3, I8 {}
|
||||
|
||||
private func foo_class(_ c: Any, _ x: Int, _ i: Int) -> Int {
|
||||
var x = x
|
||||
if (c is C0) {
|
||||
x = x &+ i
|
||||
}
|
||||
if (c is C1) {
|
||||
x = x ^ i
|
||||
}
|
||||
if (c is C2) {
|
||||
x = x &+ i
|
||||
}
|
||||
if (c is C3) {
|
||||
x = x ^ i
|
||||
}
|
||||
if (c is C4) {
|
||||
x = x &+ i
|
||||
}
|
||||
if (c is C5) {
|
||||
x = x ^ i
|
||||
}
|
||||
if (c is C6) {
|
||||
x = x &+ i
|
||||
}
|
||||
if (c is C7) {
|
||||
x = x ^ i
|
||||
}
|
||||
if (c is C8) {
|
||||
x = x &+ i
|
||||
}
|
||||
if (c is C9) {
|
||||
x = x ^ i
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
private func foo_iface(_ c: Any, _ x: Int, _ i: Int) -> Int {
|
||||
var x = x
|
||||
if (c is I0) {
|
||||
x = x &+ i
|
||||
}
|
||||
if (c is I1) {
|
||||
x = x ^ i
|
||||
}
|
||||
if (c is I2) {
|
||||
x = x &+ i
|
||||
}
|
||||
if (c is I3) {
|
||||
x = x ^ i
|
||||
}
|
||||
if (c is I4) {
|
||||
x = x &+ i
|
||||
}
|
||||
if (c is I5) {
|
||||
x = x ^ i
|
||||
}
|
||||
if (c is I6) {
|
||||
x = x &+ i
|
||||
}
|
||||
if (c is I7) {
|
||||
x = x ^ i
|
||||
}
|
||||
if (c is I8) {
|
||||
x = x &+ i
|
||||
}
|
||||
if (c is I9) {
|
||||
x = x ^ i
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func classCast() -> Int {
|
||||
let c0: Any = C0()
|
||||
let c1: Any = C1()
|
||||
let c2: Any = C2()
|
||||
let c3: Any = C3()
|
||||
let c4: Any = C4()
|
||||
let c5: Any = C5()
|
||||
let c6: Any = C6()
|
||||
let c7: Any = C7()
|
||||
let c8: Any = C8()
|
||||
let c9: Any = C9()
|
||||
|
||||
var x = 0
|
||||
for i in 0..<RunsInfo.RUNS {
|
||||
x = x &+ foo_class(c0, x, i)
|
||||
x = x &+ foo_class(c1, x, i)
|
||||
x = x &+ foo_class(c2, x, i)
|
||||
x = x &+ foo_class(c3, x, i)
|
||||
x = x &+ foo_class(c4, x, i)
|
||||
x = x &+ foo_class(c5, x, i)
|
||||
x = x &+ foo_class(c6, x, i)
|
||||
x = x &+ foo_class(c7, x, i)
|
||||
x = x &+ foo_class(c8, x, i)
|
||||
x = x &+ foo_class(c9, x, i)
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func interfaceCast() -> Int {
|
||||
let c0: Any = C0()
|
||||
let c1: Any = C1()
|
||||
let c2: Any = C2()
|
||||
let c3: Any = C3()
|
||||
let c4: Any = C4()
|
||||
let c5: Any = C5()
|
||||
let c6: Any = C6()
|
||||
let c7: Any = C7()
|
||||
let c8: Any = C8()
|
||||
let c9: Any = C9()
|
||||
|
||||
var x = 0
|
||||
for i in 0..<RunsInfo.RUNS {
|
||||
x = x &+ foo_iface(c0, x, i)
|
||||
x = x &+ foo_iface(c1, x, i)
|
||||
x = x &+ foo_iface(c2, x, i)
|
||||
x = x &+ foo_iface(c3, x, i)
|
||||
x = x &+ foo_iface(c4, x, i)
|
||||
x = x &+ foo_iface(c5, x, i)
|
||||
x = x &+ foo_iface(c6, x, i)
|
||||
x = x &+ foo_iface(c7, x, i)
|
||||
x = x &+ foo_iface(c8, x, i)
|
||||
x = x &+ foo_iface(c9, x, i)
|
||||
}
|
||||
return x
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class ClassArrayBenchmark {
|
||||
private var _data: [Value]? = nil
|
||||
var data: [Value] {
|
||||
return _data!
|
||||
}
|
||||
|
||||
init() {
|
||||
var list: [Value] = []
|
||||
for n in classValues(Constants.BENCHMARK_SIZE) {
|
||||
list.append(n)
|
||||
}
|
||||
_data = list
|
||||
}
|
||||
|
||||
func copy() -> [Value] {
|
||||
return Array(data)
|
||||
}
|
||||
|
||||
func copyManual() -> [Value] {
|
||||
var list: [Value] = []
|
||||
for item in data {
|
||||
list.append(item)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func filterAndCount() -> Int {
|
||||
return data.filter { filterLoad($0) }.count
|
||||
}
|
||||
|
||||
func filterAndMap() -> [String] {
|
||||
return data.filter { filterLoad($0) }.map { mapLoad($0) }
|
||||
}
|
||||
|
||||
func filterAndMapManual() -> [String] {
|
||||
var list: [String] = []
|
||||
for it in data {
|
||||
if (filterLoad(it)) {
|
||||
let value = mapLoad(it)
|
||||
list.append(value)
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func filter() -> [Value] {
|
||||
return data.filter { filterLoad($0) }
|
||||
}
|
||||
|
||||
func filterManual() -> [Value] {
|
||||
var list: [Value] = []
|
||||
for it in data {
|
||||
if (filterLoad(it)) {
|
||||
list.append(it)
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func countFilteredManual() -> Int {
|
||||
var count = 0
|
||||
for it in data {
|
||||
if (filterLoad(it)) {
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func countFiltered() -> Int {
|
||||
return data.count { filterLoad($0) }
|
||||
}
|
||||
|
||||
func countFilteredLocal() -> Int {
|
||||
return data.cnt { filterLoad($0) }
|
||||
}
|
||||
}
|
||||
|
||||
extension Collection {
|
||||
func count(where test: (Element) throws -> Bool) rethrows -> Int {
|
||||
return try self.filter(test).count
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class ClassBaselineBenchmark {
|
||||
|
||||
func consume() {
|
||||
for item in 1...Constants.BENCHMARK_SIZE {
|
||||
Blackhole.consume(Value(item))
|
||||
}
|
||||
}
|
||||
|
||||
func consumeField() {
|
||||
let value = Value(0)
|
||||
for item in 1...Constants.BENCHMARK_SIZE {
|
||||
value.value = item
|
||||
Blackhole.consume(value)
|
||||
}
|
||||
}
|
||||
|
||||
func allocateList() -> [Value] {
|
||||
let list = [Value](repeating: Value(0), count: Constants.BENCHMARK_SIZE)
|
||||
return list
|
||||
}
|
||||
|
||||
func allocateArray() -> [Value?] {
|
||||
let list = [Value?](repeating: nil, count: Constants.BENCHMARK_SIZE)
|
||||
return list
|
||||
}
|
||||
|
||||
func allocateListAndFill() -> [Value] {
|
||||
var list: [Value] = []
|
||||
for item in 1...Constants.BENCHMARK_SIZE {
|
||||
list.append(Value(item))
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func allocateListAndWrite() -> [Value] {
|
||||
let value = Value(0)
|
||||
var list: [Value] = []
|
||||
for _ in 1...Constants.BENCHMARK_SIZE {
|
||||
list.append(value)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func allocateArrayAndFill() -> [Value?] {
|
||||
var list = [Value?](repeating: nil, count: Constants.BENCHMARK_SIZE)
|
||||
var index = 0
|
||||
for item in 1...Constants.BENCHMARK_SIZE {
|
||||
list[index] = Value(item)
|
||||
index += 1
|
||||
}
|
||||
return list
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
class ClassListBenchmark {
|
||||
private var _data: [Value]? = nil
|
||||
var data: [Value] {
|
||||
return _data!
|
||||
}
|
||||
|
||||
init() {
|
||||
var list: [Value] = []
|
||||
for n in classValues(Constants.BENCHMARK_SIZE) {
|
||||
list.append(n)
|
||||
}
|
||||
_data = list
|
||||
}
|
||||
|
||||
func filterAndCountWithLambda() -> Int {
|
||||
return data.filter { $0.value % 2 == 0 }.count
|
||||
}
|
||||
|
||||
func filterWithLambda() -> [Value] {
|
||||
return data.filter { $0.value % 2 == 0 }
|
||||
}
|
||||
|
||||
func mapWithLambda() -> [String] {
|
||||
return data.map { String($0.value) }
|
||||
}
|
||||
|
||||
func countWithLambda() -> Int {
|
||||
return data.count { $0.value % 2 == 0 }
|
||||
}
|
||||
|
||||
func filterAndMapWithLambda() -> [String] {
|
||||
return data.filter { $0.value % 2 == 0 }.map { String($0.value) }
|
||||
}
|
||||
|
||||
func filterAndMapWithLambdaAsSequence() -> [String] {
|
||||
return data.lazy.filter { $0.value % 2 == 0 }.map { String($0.value) }
|
||||
}
|
||||
|
||||
func reduce() -> Int {
|
||||
return data.reduce(0) { if (filterLoad($1)) { return $0 + 1 } else { return $0 }}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class ClassStreamBenchmark {
|
||||
private var _data: AnySequence<Value>? = nil
|
||||
var data: AnySequence<Value> {
|
||||
return _data!
|
||||
}
|
||||
|
||||
init() {
|
||||
_data = AnySequence(classValues(Constants.BENCHMARK_SIZE))
|
||||
}
|
||||
|
||||
func copy() -> [Value] {
|
||||
return Array(data)
|
||||
}
|
||||
|
||||
func copyManual() -> [Value] {
|
||||
var list: [Value] = []
|
||||
for item in data.lazy {
|
||||
list.append(item)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func filterAndCount() -> Int {
|
||||
return data.lazy.filter { filterLoad($0) }.count
|
||||
}
|
||||
|
||||
func filterAndMap() {
|
||||
for item in (data.lazy.filter { filterLoad($0) }.map { mapLoad($0) }) {
|
||||
Blackhole.consume(item)
|
||||
}
|
||||
}
|
||||
|
||||
func filterAndMapManual() {
|
||||
for it in data.lazy {
|
||||
if (filterLoad(it)) {
|
||||
let item = mapLoad(it)
|
||||
Blackhole.consume(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func filter() {
|
||||
for item in (data.lazy.filter { filterLoad($0) }) {
|
||||
Blackhole.consume(item)
|
||||
}
|
||||
}
|
||||
|
||||
func filterManual() {
|
||||
for it in data.lazy {
|
||||
if (filterLoad(it)) {
|
||||
Blackhole.consume(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func countFilteredManual() -> Int {
|
||||
var count = 0
|
||||
for it in data.lazy {
|
||||
if (filterLoad(it)) {
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
|
||||
func reduce() -> Int {
|
||||
return data.lazy.reduce(0) {if (filterLoad($1)) { return $0 + 1 } else { return $0 }}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class CompanionObjectBenchmark {
|
||||
func invokeRegularFunction() {
|
||||
CompanionObjectBenchmark.regularCompanionObjectFunction("")
|
||||
}
|
||||
|
||||
static func regularCompanionObjectFunction(_ o: Any) -> Any {
|
||||
return o
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,365 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class CoordinatesSolverBenchmark {
|
||||
let solver: Solver
|
||||
|
||||
init() {
|
||||
let 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
|
||||
"""
|
||||
let input = CoordinatesSolverBenchmark.readTillParsed(inputValue)
|
||||
|
||||
solver = Solver(input!)
|
||||
}
|
||||
|
||||
struct Coordinate: Equatable {
|
||||
let x: Int
|
||||
let y: Int
|
||||
}
|
||||
|
||||
struct Field {
|
||||
let x: Int
|
||||
let y: Int
|
||||
let value: Int8
|
||||
func northWall() -> Bool {
|
||||
return value & 1 != 0
|
||||
}
|
||||
|
||||
func eastWall() -> Bool {
|
||||
return value & 2 != 0
|
||||
}
|
||||
|
||||
func southWall() -> Bool {
|
||||
return value & 4 != 0
|
||||
}
|
||||
|
||||
func westWall() -> Bool {
|
||||
return value & 8 != 0
|
||||
}
|
||||
|
||||
func hasObject() -> Bool {
|
||||
return value & 16 != 0
|
||||
}
|
||||
}
|
||||
|
||||
struct Input {
|
||||
let labyrinth: Labyrinth
|
||||
let nObjects: Int
|
||||
}
|
||||
|
||||
class Labyrinth {
|
||||
let width: Int
|
||||
let height: Int
|
||||
let fields: [Field]
|
||||
init(_ width: Int, _ height: Int, _ fields: Array<Field>) {
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.fields = fields
|
||||
}
|
||||
func getField(_ x: Int, _ y: Int) -> Field {
|
||||
return fields[x + y * width]
|
||||
}
|
||||
}
|
||||
|
||||
struct Output {
|
||||
let steps: [Coordinate?]
|
||||
}
|
||||
|
||||
class InputParser {
|
||||
private var rows : [[Field]] = []
|
||||
private var numObjects: Int = 0
|
||||
|
||||
private var input: Input {
|
||||
get {
|
||||
let width = rows[0].count
|
||||
var fields = [Field?](repeating: nil, count: width * rows.count)
|
||||
|
||||
for y in rows.indices {
|
||||
let row = rows[y]
|
||||
for p in (y*width)..<(y*width + width) {
|
||||
fields[p] = row[p-y*width]
|
||||
}
|
||||
}
|
||||
|
||||
let labyrinth = Labyrinth(width, rows.count, fields.filter { $0 != nil } as! Array<CoordinatesSolverBenchmark.Field>)
|
||||
|
||||
return Input(labyrinth: labyrinth, nObjects: numObjects)
|
||||
}
|
||||
}
|
||||
|
||||
func feedLine(line: String) -> Input? {
|
||||
let items = line.split(separator: " ").filter { $0 != "" }
|
||||
|
||||
if (items.count == 1) {
|
||||
numObjects = Int(items[0]) ?? 0
|
||||
return input
|
||||
} else if (items.count > 0) {
|
||||
let rowNum = rows.count
|
||||
var row = [Field?](repeating: nil, count: items.count)
|
||||
|
||||
for col in items.indices {
|
||||
row[col] = Field(x: rowNum, y: col, value: Int8(items[col]) ?? 0)
|
||||
}
|
||||
|
||||
rows.append(row as! [CoordinatesSolverBenchmark.Field])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Solver {
|
||||
private let input: Input
|
||||
init(_ input: Input) {
|
||||
self.input = input
|
||||
objects = []
|
||||
for f in input.labyrinth.fields {
|
||||
if (f.hasObject()) {
|
||||
objects.append(Coordinate(x: f.x, y: f.y))
|
||||
}
|
||||
}
|
||||
|
||||
width = input.labyrinth.width
|
||||
height = input.labyrinth.height
|
||||
maze_end = Coordinate(x: width - 1, y: height - 1)
|
||||
}
|
||||
private var objects: [Coordinate]
|
||||
|
||||
private let width: Int
|
||||
private let height: Int
|
||||
private let maze_end: Coordinate
|
||||
|
||||
private var counter: Int64 = 0
|
||||
|
||||
func solve() -> Output {
|
||||
var steps = [Coordinate]()
|
||||
|
||||
for o in objects.indices {
|
||||
var limit = input.labyrinth.width + input.labyrinth.height - 2
|
||||
|
||||
var ss: [Coordinate]? = nil
|
||||
while (ss == nil) {
|
||||
if (o == 0) {
|
||||
ss = solveWithLimit(limit, Solver.MAZE_START) { $0[$0.count - 1] == objects[0] }
|
||||
} else {
|
||||
ss = solveWithLimit(limit, objects[o - 1]) { $0[$0.count - 1] == objects[o] }
|
||||
}
|
||||
|
||||
if (ss != nil) {
|
||||
steps.append(contentsOf: ss!)
|
||||
}
|
||||
|
||||
limit += 1
|
||||
}
|
||||
}
|
||||
|
||||
var limit = input.labyrinth.width + input.labyrinth.height - 2
|
||||
|
||||
var ss: [Coordinate]? = nil
|
||||
while (ss == nil) {
|
||||
ss = solveWithLimit(limit, objects[objects.count - 1]) { $0[$0.count - 1] == maze_end }
|
||||
|
||||
if (ss != nil) {
|
||||
steps.append(contentsOf: ss!)
|
||||
}
|
||||
|
||||
limit += 1
|
||||
}
|
||||
|
||||
return createOutput(steps: steps)
|
||||
}
|
||||
|
||||
private func createOutput(steps: [Coordinate]) -> Output {
|
||||
var objects : [Coordinate] = self.objects
|
||||
var outSteps : [Coordinate?] = []
|
||||
|
||||
for step in steps {
|
||||
outSteps.append(step)
|
||||
|
||||
if (objects.contains(step)) {
|
||||
outSteps.append(nil)
|
||||
objects = objects.filter { $0 != step }
|
||||
}
|
||||
}
|
||||
|
||||
return Output(steps: outSteps)
|
||||
}
|
||||
|
||||
private func isValid(steps: [Coordinate]) -> Bool {
|
||||
counter += 1
|
||||
let coords = steps[steps.count - 1]
|
||||
let x = coords.x
|
||||
let y = coords.y
|
||||
return (!(x == input.labyrinth.width - 1 && y == input.labyrinth.height - 1)) ? false : objects.filter{ steps.contains($0) == false }.count == 0
|
||||
}
|
||||
|
||||
private func getPossibleSteps(_ now: Coordinate, _ previous: Coordinate?) -> [Coordinate] {
|
||||
let field = input.labyrinth.getField(now.x, now.y)
|
||||
|
||||
var possibleSteps: [Coordinate] = []
|
||||
|
||||
if (now.x != width - 1 && !field.eastWall()) {
|
||||
possibleSteps.append(Coordinate(x: now.x + 1, y: now.y))
|
||||
}
|
||||
if (now.x != 0 && !field.westWall()) {
|
||||
possibleSteps.append(Coordinate(x: now.x - 1, y: now.y))
|
||||
}
|
||||
if (now.y != 0 && !field.northWall()) {
|
||||
possibleSteps.append(Coordinate(x: now.x, y: now.y - 1))
|
||||
}
|
||||
if (now.y != height - 1 && !field.southWall()) {
|
||||
possibleSteps.append(Coordinate(x: now.x, y: now.y + 1))
|
||||
}
|
||||
|
||||
if (!field.hasObject() && previous != nil) {
|
||||
possibleSteps = possibleSteps.filter { $0 != previous }
|
||||
}
|
||||
|
||||
return possibleSteps
|
||||
}
|
||||
|
||||
private func solveWithLimit(_ limit: Int, _ start: Coordinate, _ validFn: ([Coordinate]) -> Bool) -> [Coordinate]? {
|
||||
var steps: [Coordinate]? = findFirstLegitSteps(nil, start, limit)
|
||||
|
||||
while (steps != nil && !validFn(steps!)) {
|
||||
steps = alter(start, nil, &steps!)
|
||||
}
|
||||
|
||||
return steps
|
||||
}
|
||||
|
||||
private func findFirstLegitSteps(_ startPrev: Coordinate?, _ start: Coordinate, _ num: Int) -> [Coordinate]? {
|
||||
var steps: [Coordinate]? = []
|
||||
|
||||
var i = 0
|
||||
while (i < num) {
|
||||
let prev: Coordinate?
|
||||
let 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]
|
||||
}
|
||||
|
||||
let possibleSteps = getPossibleSteps(state, prev)
|
||||
|
||||
if (possibleSteps.count == 0) {
|
||||
if (steps!.count == 0) {
|
||||
return nil
|
||||
}
|
||||
|
||||
steps = alter(start, startPrev, &steps!)
|
||||
if (steps == nil) {
|
||||
return nil
|
||||
}
|
||||
|
||||
i -= 1
|
||||
i += 1
|
||||
continue
|
||||
}
|
||||
|
||||
let newStep = possibleSteps[0]
|
||||
steps!.append(newStep)
|
||||
i += 1
|
||||
}
|
||||
|
||||
return steps
|
||||
}
|
||||
|
||||
private func alter(_ start: Coordinate, _ startPrev: Coordinate?, _ steps: inout [Coordinate]) -> [Coordinate]? {
|
||||
let size = steps.count
|
||||
|
||||
var i = size - 1
|
||||
while (i >= 0) {
|
||||
let current = steps[i]
|
||||
let prev = i == 0 ? start : steps[i - 1]
|
||||
let prevprev: Coordinate?
|
||||
if (i > 1) {
|
||||
prevprev = steps[i - 2]
|
||||
} else if (i == 1) {
|
||||
prevprev = start
|
||||
} else {
|
||||
prevprev = startPrev
|
||||
}
|
||||
|
||||
let alternatives = getPossibleSteps(prev, prevprev)
|
||||
let index = alternatives.firstIndex(of: current)
|
||||
|
||||
if (index != nil && index != alternatives.count - 1) {
|
||||
let newItem = alternatives[index! + 1]
|
||||
steps[i] = newItem
|
||||
|
||||
let remainder = findFirstLegitSteps(prev, newItem, size - i - 1)
|
||||
if (remainder == nil) {
|
||||
i += 1
|
||||
i -= 1
|
||||
continue
|
||||
}
|
||||
|
||||
Solver.removeAfterIndexExclusive(&steps, i)
|
||||
steps.append(contentsOf: remainder ?? [])
|
||||
|
||||
return steps
|
||||
} else {
|
||||
if (i == 0) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
i -= 1
|
||||
}
|
||||
|
||||
return steps
|
||||
}
|
||||
|
||||
|
||||
private static let MAZE_START = Coordinate(x: 0, y: 0)
|
||||
private static func removeAfterIndexExclusive(_ list: inout [Coordinate], _ index: Int) {
|
||||
let rnum = list.count - 1 - index
|
||||
|
||||
for _ in 0..<rnum {
|
||||
list.remove(at: list.count - 1)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static func readTillParsed(_ inputValue: String) -> Input? {
|
||||
let parser = InputParser()
|
||||
var input: Input? = nil
|
||||
inputValue.split(separator: "\n").forEach { line in
|
||||
input = parser.feedLine(line: String(line))
|
||||
}
|
||||
|
||||
return input
|
||||
}
|
||||
|
||||
func solve() {
|
||||
let output = solver.solve()
|
||||
|
||||
for c in output.steps {
|
||||
let value = (c == nil) ? "felvesz" : "${c.x} ${c.y}"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
public class Value: Hashable {
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
return value.hash(into: &hasher)
|
||||
}
|
||||
|
||||
public static func == (lhs: Value, rhs: Value) -> Bool {
|
||||
return lhs.value == rhs.value
|
||||
}
|
||||
|
||||
public var hashValue: Int {
|
||||
return value.hashValue
|
||||
}
|
||||
|
||||
var value: Int
|
||||
init(_ value: Int) {
|
||||
self.value = value
|
||||
}
|
||||
lazy var text = String(String(value).reversed())
|
||||
}
|
||||
|
||||
public func intValues(_ size: Int) -> [Int] {
|
||||
return Array(1...size)
|
||||
}
|
||||
|
||||
public func classValues(_ size: Int) -> [Value] {
|
||||
return intValues(size).map { Value($0) }
|
||||
}
|
||||
|
||||
public func stringValues(_ size: Int) -> [String] {
|
||||
return intValues(size).map { String($0) }
|
||||
}
|
||||
|
||||
public func filterLoad(_ v: Value) -> Bool {
|
||||
return v.text.contains(String(v.value))
|
||||
}
|
||||
|
||||
public func mapLoad(_ v: Value) -> String {
|
||||
return String(v.text.reversed())
|
||||
}
|
||||
|
||||
public func filterLoad(_ v: Int) -> Bool {
|
||||
return "0123456789".contains(String(v))
|
||||
}
|
||||
|
||||
public func mapLoad(_ v: Int) -> String {
|
||||
return String(v)
|
||||
}
|
||||
|
||||
public func filterSome(_ v: Int) -> Bool {
|
||||
return v % 7 == 0 || v % 11 == 0
|
||||
}
|
||||
|
||||
public func filterPrime(_ v: Int) -> Bool {
|
||||
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
|
||||
}
|
||||
|
||||
extension Array where Element: Value {
|
||||
@inlinable func cnt(predicate: (Value) -> Bool) -> Int {
|
||||
var count = 0
|
||||
for element in self {
|
||||
if (predicate(element)) {
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
}
|
||||
|
||||
extension Array where Element == Int {
|
||||
@inlinable func cnt(predicate: (Int) -> Bool) -> Int {
|
||||
var count = 0
|
||||
for element in self {
|
||||
if (predicate(element)) {
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
}
|
||||
|
||||
extension Sequence where Element == Int {
|
||||
@inlinable func cnt(predicate: (Int) -> Bool) -> Int {
|
||||
var count = 0
|
||||
for element in self {
|
||||
if (predicate(element)) {
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class DefaultArgumentBenchmark {
|
||||
private var arg = 0
|
||||
|
||||
init() {
|
||||
arg = Int.random(in: 0...100)
|
||||
}
|
||||
|
||||
|
||||
func sumTwo(_ first: Int, _ second: Int = 0) -> Int {
|
||||
return first + second
|
||||
}
|
||||
|
||||
|
||||
func sumFour(_ first: Int, _ second: Int = 0, _ third: Int = 1, _ fourth: Int = 1) -> Int {
|
||||
return first + second + third + fourth
|
||||
}
|
||||
|
||||
func sumEight(_ first: Int, _ second: Int = 0, _ third: Int = 1, _ fourth: Int = 1, _ fifth: Int = 1, _ sixth: Int = 1, _ seventh: Int = 1, _ eighth: Int = 1) -> Int {
|
||||
return first + second + third + fourth + fifth + sixth + seventh + eighth
|
||||
}
|
||||
|
||||
func testOneOfTwo() {
|
||||
sumTwo(arg)
|
||||
}
|
||||
|
||||
func testTwoOfTwo() {
|
||||
sumTwo(arg, arg)
|
||||
}
|
||||
|
||||
func testOneOfFour() {
|
||||
sumFour(arg)
|
||||
}
|
||||
|
||||
func testFourOfFour() {
|
||||
sumFour(arg, arg, arg, arg)
|
||||
}
|
||||
|
||||
func testOneOfEight() {
|
||||
sumEight(arg)
|
||||
}
|
||||
|
||||
func testEightOfEight() {
|
||||
sumEight(arg, arg, arg, arg, arg, arg, arg, arg)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class ElvisBenchmark {
|
||||
|
||||
class Value {
|
||||
var value: Int
|
||||
init(_ value: Int) {
|
||||
self.value = value
|
||||
}
|
||||
}
|
||||
|
||||
var array : [Value?] = []
|
||||
|
||||
init() {
|
||||
array = (0 ..< Constants.BENCHMARK_SIZE).map { _ in
|
||||
if (Int.random(in: 0...Constants.BENCHMARK_SIZE) < Constants.BENCHMARK_SIZE / 10) {
|
||||
return nil
|
||||
} else {
|
||||
return Value(Int.random(in: 0...100))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testElvis() {
|
||||
for obj in array {
|
||||
Blackhole.consume(obj?.value ?? 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
struct FibonacciGenerator: Sequence, IteratorProtocol {
|
||||
var a = 0
|
||||
var b = 1
|
||||
var current = 1
|
||||
mutating func next() -> Int? {
|
||||
defer {
|
||||
current = a + b
|
||||
a = b
|
||||
b = current
|
||||
}
|
||||
return current
|
||||
}
|
||||
}
|
||||
|
||||
extension Int64 {
|
||||
func isPalindrome() -> Bool {
|
||||
return String(self) == String(String(self).reversed())
|
||||
}
|
||||
}
|
||||
|
||||
extension Range where Bound == Int {
|
||||
@inlinable func sum(_ predicate: (Int) -> Bool) -> Int {
|
||||
var sum = 0
|
||||
for i in self {
|
||||
if (predicate(i)) {
|
||||
sum += i
|
||||
}
|
||||
}
|
||||
return sum
|
||||
}
|
||||
}
|
||||
|
||||
extension Sequence where Element == Int {
|
||||
@inlinable func sum(_ predicate: (Int) -> Bool) -> Int {
|
||||
var sum = 0
|
||||
for i in self {
|
||||
if (predicate(i)) {
|
||||
sum += i
|
||||
}
|
||||
}
|
||||
return sum
|
||||
}
|
||||
}
|
||||
|
||||
extension Sequence {
|
||||
func takeWhile(condition: (Element) -> Bool) -> [Element] {
|
||||
var result: [Element] = []
|
||||
for x in self {
|
||||
guard condition(x) else { break }
|
||||
result.append(x)
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
class EulerBenchmark {
|
||||
func problem1bySequence() -> Int {
|
||||
return AnySequence<Int>(1...Constants.BENCHMARK_SIZE).lazy.sum( { $0 % 3 == 0 || $0 % 5 == 0} )
|
||||
}
|
||||
|
||||
func problem1() -> Int {
|
||||
return (1...Constants.BENCHMARK_SIZE).sum( { $0 % 3 == 0 || $0 % 5 == 0} )
|
||||
}
|
||||
|
||||
func problem2() -> Int {
|
||||
return FibonacciGenerator().takeWhile { $0 < Constants.BENCHMARK_SIZE }.sum { $0 % 2 == 0 }
|
||||
}
|
||||
|
||||
func problem4() -> Int64 {
|
||||
let s: Int64 = Int64(Constants.BENCHMARK_SIZE)
|
||||
let maxLimit = (s-1)*(s-1)
|
||||
let minLimit = (s/10)*(s/10)
|
||||
let maxDiv = Constants.BENCHMARK_SIZE-1
|
||||
let minDiv = Constants.BENCHMARK_SIZE/10
|
||||
for i in stride(from: maxLimit, through: minLimit, by: -1) {
|
||||
if (!i.isPalindrome()) {
|
||||
continue
|
||||
}
|
||||
for j in minDiv...maxDiv {
|
||||
if (i % Int64(j) == 0) {
|
||||
let res = i / Int64(j)
|
||||
if ((Int64(minDiv)...Int64(maxDiv)).contains(res)) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
private let veryLongNumber = """
|
||||
73167176531330624919225119674426574742355349194934
|
||||
96983520312774506326239578318016984801869478851843
|
||||
85861560789112949495459501737958331952853208805511
|
||||
12540698747158523863050715693290963295227443043557
|
||||
66896648950445244523161731856403098711121722383113
|
||||
62229893423380308135336276614282806444486645238749
|
||||
30358907296290491560440772390713810515859307960866
|
||||
70172427121883998797908792274921901699720888093776
|
||||
65727333001053367881220235421809751254540594752243
|
||||
52584907711670556013604839586446706324415722155397
|
||||
53697817977846174064955149290862569321978468622482
|
||||
83972241375657056057490261407972968652414535100474
|
||||
82166370484403199890008895243450658541227588666881
|
||||
16427171479924442928230863465674813919123162824586
|
||||
17866458359124566529476545682848912883142607690042
|
||||
24219022671055626321111109370544217506941658960408
|
||||
07198403850962455444362981230987879927244284909188
|
||||
84580156166097919133875499200524063689912560717606
|
||||
05886116467109405077541002256983155200055935729725
|
||||
71636269561882670428252483600823257530420752963450
|
||||
"""
|
||||
|
||||
func problem8() -> Int64 {
|
||||
var productSize = 13
|
||||
if ((1...10).contains(Constants.BENCHMARK_SIZE)) {
|
||||
productSize = 4
|
||||
} else if ((11...1000).contains(Constants.BENCHMARK_SIZE)) {
|
||||
productSize = 8
|
||||
}
|
||||
var digits: [Int] = []
|
||||
for digit in veryLongNumber {
|
||||
if (("0"..."9").contains(digit)) {
|
||||
if let number = Int(String(digit)) {
|
||||
if let secNumber = Int(String("0")) {
|
||||
digits.append(number - secNumber)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var largest: Int64 = 0
|
||||
for i in 0...digits.count - productSize - 1 {
|
||||
var product: Int64 = 1
|
||||
for j in 0...productSize-1 {
|
||||
product *= Int64(digits[i+j])
|
||||
}
|
||||
if (product > largest) {
|
||||
largest = product
|
||||
}
|
||||
}
|
||||
return largest
|
||||
}
|
||||
|
||||
func problem9() -> Int64 {
|
||||
for c in Constants.BENCHMARK_SIZE/3...Constants.BENCHMARK_SIZE-3 {
|
||||
let c2 = Int64(c) * Int64(c)
|
||||
for b in (Constants.BENCHMARK_SIZE-c)/2..<c {
|
||||
if (b+c >= Constants.BENCHMARK_SIZE) {
|
||||
break
|
||||
}
|
||||
let a = Constants.BENCHMARK_SIZE - b - c
|
||||
if (a >= b) {
|
||||
continue
|
||||
}
|
||||
let b2 = Int64(b) * Int64(b)
|
||||
let a2 = Int64(a) * Int64(a)
|
||||
if (c2 == b2 + a2) {
|
||||
return Int64(a) * Int64(b) * Int64(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
class Children {
|
||||
let left: Int
|
||||
let right: Int
|
||||
init(_ left: Int, _ right: Int) {
|
||||
self.left = left
|
||||
self.right = right
|
||||
}
|
||||
}
|
||||
|
||||
func problem14() -> [Int] {
|
||||
// Build a tree
|
||||
// index is produced from first & second
|
||||
let tree = (0..<Constants.BENCHMARK_SIZE).map { i in Children(i*2, (i>4 && (i+2) % 6 == 0) ? (i-1)/3 : 0)}
|
||||
// Find longest chain by DFS
|
||||
func dfs(_ begin: Int) -> [Int] {
|
||||
if (begin == 0 || begin >= Constants.BENCHMARK_SIZE) {
|
||||
return []
|
||||
}
|
||||
let left = dfs(tree[begin].left)
|
||||
let right = dfs(tree[begin].right)
|
||||
return [begin] + ((left.count > right.count) ? left : right)
|
||||
}
|
||||
return dfs(1)
|
||||
}
|
||||
|
||||
class Way {
|
||||
let length: Int
|
||||
let next: Int
|
||||
init(_ length: Int, _ next: Int) {
|
||||
self.length = length
|
||||
self.next = next
|
||||
}
|
||||
}
|
||||
|
||||
func problem14full() -> [Int] {
|
||||
var map: [Int: Way] = [:]
|
||||
// Starting point
|
||||
map[1] = Way(0, 0)
|
||||
// Check all other numbers
|
||||
var bestNum = 0
|
||||
var bestLen = 0
|
||||
func go(_ begin: Int) -> Way {
|
||||
let res = map[begin]
|
||||
if (res != nil) {
|
||||
return res!
|
||||
}
|
||||
let next = (begin % 2 == 0) ? begin/2 : 3*begin+1
|
||||
let childRes = go(next)
|
||||
let myRes = Way(childRes.length + 1, next)
|
||||
map[begin] = myRes
|
||||
return myRes
|
||||
}
|
||||
for i in 2...Constants.BENCHMARK_SIZE-1 {
|
||||
let res = go(i)
|
||||
if (res.length > bestLen) {
|
||||
bestLen = res.length
|
||||
bestNum = i
|
||||
}
|
||||
}
|
||||
func unroll(_ begin: Int) -> [Int] {
|
||||
if (begin == 0) {
|
||||
return []
|
||||
}
|
||||
let next = map[begin]?.next ?? 0
|
||||
return [begin] + unroll(next)
|
||||
}
|
||||
return unroll(bestNum)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class FibonacciBenchmark {
|
||||
func calcClassic() -> Int64 {
|
||||
var a: Int64 = 1
|
||||
var b: Int64 = 2
|
||||
let size = Constants.BENCHMARK_SIZE
|
||||
for _ in 0...size-1 {
|
||||
let next = a &+ b
|
||||
a = b
|
||||
b = next
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func calc() -> Int64 {
|
||||
var a: Int64 = 1
|
||||
var b: Int64 = 2
|
||||
for _ in stride(from: Constants.BENCHMARK_SIZE, through: 1, by: -1) {
|
||||
let next = a &+ b
|
||||
a = b
|
||||
b = next
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func calcWithProgression() -> Int64 {
|
||||
var a: Int64 = 1
|
||||
var b: Int64 = 2
|
||||
for _ in stride(from: 1, through: 2*Constants.BENCHMARK_SIZE-1, by: 2) {
|
||||
let next = a &+ b
|
||||
a = b
|
||||
b = next
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func calcSquare() -> Int64 {
|
||||
var a: Int64 = 1
|
||||
var b: Int64 = 2
|
||||
let s = Int64(Constants.BENCHMARK_SIZE)
|
||||
let limit = s*s
|
||||
|
||||
for _ in stride(from: limit, through: 1, by: -1) {
|
||||
let next = a &+ b
|
||||
a = b
|
||||
b = next
|
||||
}
|
||||
return b
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
class ForLoopsBenchmark {
|
||||
|
||||
private let array: [Int] = (1...Constants.BENCHMARK_SIZE).map { $0 }
|
||||
|
||||
private let charArray: [Character] = (1...Constants.BENCHMARK_SIZE).map { Character(UnicodeScalar($0) ?? "0") }
|
||||
|
||||
private lazy var string: String = String(charArray)
|
||||
|
||||
private let floatArray: [Float] = (1...Constants.BENCHMARK_SIZE).map { Float($0) }
|
||||
|
||||
func arrayLoop() -> Int64 {
|
||||
var sum: Int64 = 0
|
||||
for e in array {
|
||||
sum += Int64(e)
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
|
||||
func charArrayLoop() -> Int64 {
|
||||
var sum : Int64 = 0
|
||||
for e in charArray {
|
||||
sum += Int64(String(e)) ?? 0
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
func stringLoop() -> Int64 {
|
||||
var sum: Int64 = 0
|
||||
for e in string {
|
||||
sum = sum &+ (Int64(String(e)) ?? 0)
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
func floatArrayLoop() -> Double {
|
||||
var sum = 0.0
|
||||
for e in floatArray {
|
||||
sum += Double(e)
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
func arrayIndicesLoop() -> Int64 {
|
||||
var sum = 0
|
||||
for i in array.indices {
|
||||
sum += array[i]
|
||||
}
|
||||
return Int64(sum)
|
||||
}
|
||||
|
||||
func charArrayIndicesLoop() -> Int64 {
|
||||
var sum: Int64 = 0
|
||||
for i in charArray.indices {
|
||||
sum += Int64(String(charArray[i])) ?? 0
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
func stringIndicesLoop() -> Int64 {
|
||||
var sum: Int64 = 0
|
||||
for i in string.indices {
|
||||
sum = sum &+ Int64(string[i].hashValue)
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
func floatArrayIndicesLoop() -> Double {
|
||||
var sum = 0.0
|
||||
for i in floatArray.indices {
|
||||
sum += Double(floatArray[i])
|
||||
}
|
||||
return sum
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
func load(_ value: Int, _ size: Int) -> Int {
|
||||
var acc = 0
|
||||
for _ in 0...size {
|
||||
acc = acc ^ value.hashValue
|
||||
}
|
||||
return acc
|
||||
}
|
||||
|
||||
@inlinable
|
||||
func loadInline(_ value: Int, _ size: Int) -> Int {
|
||||
var acc = 0
|
||||
for _ in 0...size {
|
||||
acc = acc ^ value.hashValue
|
||||
}
|
||||
return acc
|
||||
}
|
||||
|
||||
func loadGeneric<T: Hashable>(_ value: T, _ size: Int) -> Int {
|
||||
var acc = 0
|
||||
for _ in 0...size {
|
||||
acc = acc ^ value.hashValue
|
||||
}
|
||||
return acc
|
||||
}
|
||||
|
||||
@inlinable
|
||||
func loadGenericInline<T: Hashable>(_ value: T, _ size: Int) -> Int {
|
||||
var acc = 0
|
||||
for _ in 0...size {
|
||||
acc = acc ^ value.hashValue
|
||||
}
|
||||
return acc
|
||||
}
|
||||
|
||||
open class InlineBenchmark {
|
||||
private var value = 2138476523
|
||||
|
||||
func calculate() -> Int {
|
||||
return load(value, Constants.BENCHMARK_SIZE)
|
||||
}
|
||||
|
||||
func calculateInline() -> Int {
|
||||
return loadInline(value, Constants.BENCHMARK_SIZE)
|
||||
}
|
||||
|
||||
func calculateGeneric() -> Int {
|
||||
return loadGeneric(value, Constants.BENCHMARK_SIZE)
|
||||
}
|
||||
|
||||
func calculateGenericInline() -> Int {
|
||||
return loadGenericInline(value, Constants.BENCHMARK_SIZE)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class IntArrayBenchmark {
|
||||
private var _data: [Int]? = nil
|
||||
var data: [Int] {
|
||||
get {
|
||||
return _data!
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
var list: [Int] = []
|
||||
list.reserveCapacity(Constants.BENCHMARK_SIZE)
|
||||
for n in intValues(Constants.BENCHMARK_SIZE) {
|
||||
list.append(n)
|
||||
}
|
||||
_data = list
|
||||
}
|
||||
|
||||
func copy() -> [Int] {
|
||||
return Array(data)
|
||||
}
|
||||
|
||||
func copyManual() -> [Int] {
|
||||
var list: [Int] = []
|
||||
for item in data {
|
||||
list.append(item)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func filterAndCount() -> Int {
|
||||
return data.filter { filterLoad($0) }.count
|
||||
}
|
||||
|
||||
func filterSomeAndCount() -> Int {
|
||||
return data.filter { Ring.filterSome($0) }.count
|
||||
}
|
||||
|
||||
func filterAndMap() -> [String] {
|
||||
return data.filter { filterLoad($0) }.map { mapLoad($0) }
|
||||
}
|
||||
|
||||
func filterAndMapManual() -> [String] {
|
||||
var list: [String] = []
|
||||
for it in data {
|
||||
if (filterLoad(it)) {
|
||||
let value = mapLoad(it)
|
||||
list.append(value)
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func filter() -> [Int] {
|
||||
return data.filter { filterLoad($0) }
|
||||
}
|
||||
|
||||
func filterSome() -> [Int] {
|
||||
return data.filter { Ring.filterSome($0) }
|
||||
}
|
||||
|
||||
func filterPrime() -> [Int] {
|
||||
return data.filter { Ring.filterPrime($0) }
|
||||
}
|
||||
|
||||
func filterManual() -> [Int] {
|
||||
var list: [Int] = []
|
||||
for it in data {
|
||||
if (filterLoad(it)) {
|
||||
list.append(it)
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func filterSomeManual() -> [Int] {
|
||||
var list: [Int] = []
|
||||
for it in data {
|
||||
if (Ring.filterSome(it)) {
|
||||
list.append(it)
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func countFilteredManual() -> Int {
|
||||
var count = 0
|
||||
for it in data {
|
||||
if (filterLoad(it)) {
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func countFilteredSomeManual() -> Int {
|
||||
var count = 0
|
||||
for it in data {
|
||||
if (Ring.filterSome(it)) {
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func countFilteredPrimeManual() -> Int {
|
||||
var count = 0
|
||||
for it in data {
|
||||
if (Ring.filterPrime(it)) {
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func countFiltered() -> Int {
|
||||
return data.count { filterLoad($0) }
|
||||
}
|
||||
|
||||
func countFilteredSome() -> Int {
|
||||
return data.count { Ring.filterSome($0) }
|
||||
}
|
||||
|
||||
func countFilteredPrime() -> Int {
|
||||
let res = data.count { Ring.filterPrime($0) }
|
||||
return res
|
||||
}
|
||||
|
||||
func countFilteredLocal() -> Int {
|
||||
return data.cnt { filterLoad($0) }
|
||||
}
|
||||
|
||||
func countFilteredSomeLocal() -> Int {
|
||||
return data.cnt { Ring.filterSome($0) }
|
||||
}
|
||||
|
||||
func reduce() -> Int {
|
||||
return data.reduce(0) { if (filterLoad($1)) { return $0 + 1 } else { return $0 } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class IntBaselineBenchmark {
|
||||
|
||||
func consume() {
|
||||
for item in 1...Constants.BENCHMARK_SIZE {
|
||||
Blackhole.consume(item)
|
||||
}
|
||||
}
|
||||
|
||||
func allocateArray() -> [Int] {
|
||||
var list: [Int] = []
|
||||
list.reserveCapacity(Constants.BENCHMARK_SIZE)
|
||||
return list
|
||||
}
|
||||
|
||||
func allocateArrayAndFill() -> [Int] {
|
||||
var list: [Int] = []
|
||||
list.reserveCapacity(Constants.BENCHMARK_SIZE)
|
||||
for item in 1...Constants.BENCHMARK_SIZE {
|
||||
list.append(item)
|
||||
}
|
||||
return list
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class IntStreamBenchmark {
|
||||
private var _data: AnySequence<Int>? = nil
|
||||
var data: AnySequence<Int> {
|
||||
return _data!
|
||||
}
|
||||
|
||||
init() {
|
||||
_data = AnySequence(intValues(Constants.BENCHMARK_SIZE))
|
||||
}
|
||||
|
||||
func copy() -> [Int] {
|
||||
return Array(data)
|
||||
}
|
||||
|
||||
func copyManual() -> [Int] {
|
||||
var list: [Int] = []
|
||||
for item in data.lazy {
|
||||
list.append(item)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func filterAndCount() -> Int {
|
||||
return data.lazy.filter { filterLoad($0) }.count
|
||||
}
|
||||
|
||||
func filterAndMap() {
|
||||
for item in (data.lazy.filter { filterLoad($0) }.map { mapLoad($0) }) {
|
||||
Blackhole.consume(item)
|
||||
}
|
||||
}
|
||||
|
||||
func filterAndMapManual() {
|
||||
for it in data.lazy {
|
||||
if (filterLoad(it)) {
|
||||
let item = mapLoad(it)
|
||||
Blackhole.consume(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func filter() {
|
||||
for item in (data.lazy.filter { filterLoad($0) }) {
|
||||
Blackhole.consume(item)
|
||||
}
|
||||
}
|
||||
|
||||
func filterManual() {
|
||||
for it in data.lazy {
|
||||
if (filterLoad(it)) {
|
||||
Blackhole.consume(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func countFilteredManual() -> Int {
|
||||
var count = 0
|
||||
for it in data.lazy {
|
||||
if (filterLoad(it)) {
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func countFiltered() -> Int {
|
||||
return data.lazy.count { filterLoad($0) }
|
||||
}
|
||||
|
||||
func countFilteredLocal() -> Int {
|
||||
return data.lazy.cnt { filterLoad($0) }
|
||||
}
|
||||
|
||||
func reduce() -> Int {
|
||||
return data.lazy.reduce(0) { if (filterLoad($1)) { return $0 + 1 } else {return $0 } }
|
||||
}
|
||||
}
|
||||
|
||||
extension LazySequence {
|
||||
func count(where test: (Element) throws -> Bool) rethrows -> Int {
|
||||
return try self.filter(test).count
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class LambdaBenchmark {
|
||||
@inlinable
|
||||
public func runLambda<T>(_ x: () -> T) -> T {
|
||||
return x()
|
||||
}
|
||||
|
||||
private func runLambdaNoInline<T>(_ x: () -> T) -> T {
|
||||
return x()
|
||||
}
|
||||
|
||||
init() {
|
||||
Constants.globalAddendum = Int.random(in: 0 ..< 20)
|
||||
}
|
||||
|
||||
func noncapturingLambda() -> Int {
|
||||
var x: Int = 0
|
||||
for _ in 0...Constants.BENCHMARK_SIZE {
|
||||
x += runLambda { Constants.globalAddendum }
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func noncapturingLambdaNoInline() -> Int {
|
||||
var x: Int = 0
|
||||
for _ in 0...Constants.BENCHMARK_SIZE {
|
||||
x += runLambdaNoInline { Constants.globalAddendum }
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func capturingLambda() -> Int {
|
||||
let addendum = Constants.globalAddendum + 1
|
||||
var x: Int = 0
|
||||
for _ in 0...Constants.BENCHMARK_SIZE {
|
||||
x += runLambda { addendum }
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func capturingLambdaNoInline() -> Int {
|
||||
let addendum = Constants.globalAddendum + 1
|
||||
var x: Int = 0
|
||||
for _ in 0...Constants.BENCHMARK_SIZE {
|
||||
x += runLambdaNoInline { addendum }
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func mutatingLambda() -> Int {
|
||||
var x: Int = 0
|
||||
for _ in 0...Constants.BENCHMARK_SIZE {
|
||||
runLambda { x += Constants.globalAddendum }
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func mutatingLambdaNoInline() -> Int {
|
||||
var x: Int = 0
|
||||
for _ in 0...Constants.BENCHMARK_SIZE {
|
||||
runLambdaNoInline { x += Constants.globalAddendum }
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func methodReference() -> Int {
|
||||
var x: Int = 0
|
||||
for _ in 0...Constants.BENCHMARK_SIZE {
|
||||
x += runLambda(referenced)
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func methodReferenceNoInline() -> Int {
|
||||
var x: Int = 0
|
||||
for _ in 0...Constants.BENCHMARK_SIZE {
|
||||
x += runLambdaNoInline(referenced)
|
||||
}
|
||||
return x
|
||||
}
|
||||
}
|
||||
|
||||
private func referenced() -> Int {
|
||||
return Constants.globalAddendum
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class LoopBenchmark {
|
||||
var array: [Value]
|
||||
|
||||
init() {
|
||||
var list: [Value] = []
|
||||
for n in classValues(Constants.BENCHMARK_SIZE) {
|
||||
list.append(n)
|
||||
}
|
||||
array = list
|
||||
}
|
||||
|
||||
func arrayLoop() {
|
||||
for x in array {
|
||||
Blackhole.consume(x)
|
||||
}
|
||||
}
|
||||
|
||||
func arrayIndexLoop() {
|
||||
for i in array.indices {
|
||||
Blackhole.consume(array[i])
|
||||
}
|
||||
}
|
||||
|
||||
func rangeLoop() {
|
||||
for i in 0...Constants.BENCHMARK_SIZE {
|
||||
Blackhole.consume(i)
|
||||
}
|
||||
}
|
||||
|
||||
func arrayWhileLoop() {
|
||||
var i = 0
|
||||
let s = array.count
|
||||
while (i < s) {
|
||||
Blackhole.consume(array[i])
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
|
||||
func arrayForeachLoop() {
|
||||
array.forEach { Blackhole.consume($0) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class Pair: Hashable {
|
||||
|
||||
init(_ pair: (Int, Int)) {
|
||||
self.pair = pair
|
||||
}
|
||||
|
||||
public var pair: (Int, Int)
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(pair.0)
|
||||
hasher.combine(pair.1)
|
||||
}
|
||||
|
||||
public static func == (lhs: Pair, rhs: Pair) -> Bool {
|
||||
return lhs.pair == rhs.pair
|
||||
}
|
||||
|
||||
public var hashValue: Int {
|
||||
var hasher = Hasher()
|
||||
self.hash(into: &hasher)
|
||||
return hasher.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
class KMatrix {
|
||||
let rows: Int
|
||||
let columns: Int
|
||||
internal init(_ rows: Int, _ columns: Int) {
|
||||
self.rows = rows
|
||||
self.columns = columns
|
||||
for row in 0...rows-1 {
|
||||
for col in 0...columns-1 {
|
||||
matrix[Pair((row, col))] = Double.random(in: 0 ..< 100)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var matrix: [Pair: Double] = [:]
|
||||
|
||||
func get(row: Int, col: Int) -> Double {
|
||||
return get(Pair((row, col)))
|
||||
}
|
||||
|
||||
func get(_ pair: Pair) -> Double {
|
||||
return matrix[pair] ?? 0.0
|
||||
}
|
||||
|
||||
func put(_ pair: Pair, _ elem: Double) {
|
||||
matrix[pair] = elem
|
||||
}
|
||||
|
||||
static func +=(lhs: inout KMatrix, rhs:KMatrix) {
|
||||
for entry in lhs.matrix {
|
||||
lhs.put(entry.key, entry.value + rhs.get(entry.key))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MatrixMapBenchmark {
|
||||
|
||||
func add() -> KMatrix {
|
||||
var rows = Constants.BENCHMARK_SIZE
|
||||
var cols = 1
|
||||
while (rows > cols) {
|
||||
rows /= 2
|
||||
cols *= 2
|
||||
}
|
||||
var a = KMatrix(rows, cols)
|
||||
let b = KMatrix(rows, cols)
|
||||
a += b
|
||||
return a
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
struct UnsupportedOperationException: Error {
|
||||
let message: String
|
||||
|
||||
}
|
||||
|
||||
class Leaf<T : Equatable> : NodeEntity<T>, Equatable {
|
||||
static func == (lhs: Leaf<T>, rhs: Leaf<T>) -> Bool {
|
||||
return lhs.value == rhs.value
|
||||
}
|
||||
|
||||
var value: T
|
||||
|
||||
init(_ value: T) {
|
||||
self.value = value
|
||||
}
|
||||
|
||||
override func toString() -> String {
|
||||
return "L{$value}"
|
||||
}
|
||||
}
|
||||
|
||||
class NodeEntity<T: Equatable>: Node {
|
||||
func toString() -> String {
|
||||
return ""
|
||||
}
|
||||
|
||||
func set(x: Int, y: Int, z: Int, value: T, depth: Int) throws -> Bool {
|
||||
throw UnsupportedOperationException(message: "set on Leaf element")
|
||||
}
|
||||
}
|
||||
|
||||
private protocol Node {
|
||||
associatedtype T
|
||||
|
||||
func set(x: Int, y: Int, z: Int, value: T, depth: Int) throws -> Bool
|
||||
func toString() -> String
|
||||
}
|
||||
|
||||
class Branch<T: Equatable> : NodeEntity<T> {
|
||||
var nodes = [NodeEntity<T>?](repeating: nil, count: 8)
|
||||
|
||||
override init() {}
|
||||
|
||||
init(_ value: T, _ exclude: Int) {
|
||||
var i = 0
|
||||
while (i < 8) {
|
||||
if (i != exclude) {
|
||||
nodes[i] = Leaf(value)
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
|
||||
private func canClusterize(_ value: T) -> Bool {
|
||||
var i = 0
|
||||
while (i < 8) {
|
||||
let w = nodes[i]
|
||||
if (w == nil || !(w is Leaf) || value != (w as? Leaf)?.value) {
|
||||
return false
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override func set(x: Int, y: Int, z: Int, value: T, depth: Int) throws -> Bool {
|
||||
let branchIndex = OctoTree<T>.number(x, y, z, depth)
|
||||
let node = nodes[branchIndex]
|
||||
if (node == nil) {
|
||||
if (depth == 0) {
|
||||
nodes[branchIndex] = Leaf(value)
|
||||
return canClusterize(value)
|
||||
} else {
|
||||
nodes[branchIndex] = Branch<T>()
|
||||
}
|
||||
} else if let leaf = node as? Leaf<T> {
|
||||
if (leaf.value == value) {
|
||||
return false
|
||||
} else if (depth == 0) {
|
||||
leaf.value = value
|
||||
return canClusterize(value)
|
||||
}
|
||||
nodes[branchIndex] = Branch(leaf.value, OctoTree<T>.number(x, y, z, depth - 1))
|
||||
}
|
||||
|
||||
if (try nodes[branchIndex]!.set(x: x, y: y, z: z, value: value, depth: depth - 1)) {
|
||||
nodes[branchIndex] = Leaf(value)
|
||||
return canClusterize(value)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
override func toString() -> String {
|
||||
return nodes.map { $0?.toString() ?? "null" }.joined(separator: ",")
|
||||
}
|
||||
}
|
||||
|
||||
class OctoTree<T: Equatable> {
|
||||
let depth: Int
|
||||
|
||||
init(_ depth: Int) {
|
||||
self.depth = depth
|
||||
}
|
||||
|
||||
private var root: NodeEntity<T>? = nil
|
||||
private var actual = false
|
||||
|
||||
func get(_ x: Int, _ y: Int, _ z: Int) -> T? {
|
||||
var dep = depth
|
||||
var iter = root
|
||||
while (true) {
|
||||
if (iter == nil) {
|
||||
return nil
|
||||
} else if let leaf = iter as? Leaf<T> {
|
||||
return leaf.value
|
||||
}
|
||||
|
||||
dep -= 1
|
||||
iter = (iter as! Branch<T>).nodes[OctoTree<T>.number(x, y, z, dep)]
|
||||
}
|
||||
}
|
||||
|
||||
func set(x: Int, y: Int, z: Int, value: T) {
|
||||
if (root == nil) {
|
||||
root = Branch()
|
||||
}
|
||||
do {
|
||||
if (try root!.set(x: x, y: y, z: z, value: value, depth: depth - 1)) {
|
||||
root = Leaf(value)
|
||||
}
|
||||
} catch {
|
||||
print("Exception")
|
||||
}
|
||||
actual = false
|
||||
}
|
||||
|
||||
func toString() -> String {
|
||||
return root?.toString() ?? ""
|
||||
}
|
||||
|
||||
static func number(_ x: Int, _ y: Int, _ z: Int, _ depth: Int) -> Int {
|
||||
let mask = 1 << depth
|
||||
if (x & mask != 0) {
|
||||
if (y & mask != 0) {
|
||||
if (z & mask != 0) {
|
||||
return 7
|
||||
}
|
||||
return 6
|
||||
}
|
||||
if (z & mask != 0) {
|
||||
return 5
|
||||
}
|
||||
return 4
|
||||
}
|
||||
if (y & mask != 0) {
|
||||
if (z & mask != 0) {
|
||||
return 3
|
||||
}
|
||||
return 2
|
||||
}
|
||||
if (z & mask != 0) {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func octoTest() {
|
||||
let tree = OctoTree<Bool>(4)
|
||||
let to = (2 << tree.depth)
|
||||
|
||||
var x = 0
|
||||
var y = 0
|
||||
var z = 0
|
||||
|
||||
while (x < to) {
|
||||
y = 0
|
||||
while (y < to) {
|
||||
z = 0
|
||||
while (z < to) {
|
||||
let c = (z + to * y + to * to * x) % 2 == 0
|
||||
|
||||
tree.set(x: x, y: y, z: z, value: c)
|
||||
z += 1
|
||||
}
|
||||
y += 1
|
||||
}
|
||||
x += 1
|
||||
}
|
||||
|
||||
x = 0
|
||||
y = 0
|
||||
z = 0
|
||||
while (x < to) {
|
||||
y = 0
|
||||
while (y < to) {
|
||||
z = 0
|
||||
while (z < to) {
|
||||
let c = (z + to * y + to * to * x) % 2 == 0
|
||||
|
||||
let res = tree.get(x, y, z)
|
||||
|
||||
assert(res == c)
|
||||
z += 1
|
||||
}
|
||||
y += 1
|
||||
}
|
||||
x += 1
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class AnyInstance {}
|
||||
|
||||
let OBJ = AnyInstance()
|
||||
|
||||
class ParameterNotNullAssertionBenchmark {
|
||||
|
||||
func methodWithOneNotnullParameter(_ p: Any) -> Any {
|
||||
return p
|
||||
}
|
||||
|
||||
private func privateMethodWithOneNotnullParameter(_ p: Any) -> Any {
|
||||
return p
|
||||
}
|
||||
|
||||
func methodWithTwoNotnullParameters(_ p: Any, _ p2: Any) -> Any {
|
||||
return p
|
||||
}
|
||||
|
||||
private func privateMethodWithTwoNotnullParameters(_ p: Any, _ p2: Any) -> Any {
|
||||
return p
|
||||
}
|
||||
|
||||
func methodWithEightNotnullParameters(_ p: Any, _ p2: Any, _ p3: Any, _ p4: Any, _ p5: Any, _ p6: Any, _ p7: Any, _ p8: Any) -> Any {
|
||||
return p
|
||||
}
|
||||
|
||||
private func privateMethodWithEightNotnullParameters(_ p: Any, _ p2: Any, _ p3: Any, _ p4: Any, _ p5: Any, _ p6: Any, _ p7: Any, _ p8: Any) -> Any {
|
||||
return p
|
||||
}
|
||||
|
||||
func invokeOneArgWithNullCheck() -> Any {
|
||||
return methodWithOneNotnullParameter(OBJ)
|
||||
}
|
||||
|
||||
func invokeOneArgWithoutNullCheck() -> Any {
|
||||
return privateMethodWithOneNotnullParameter(OBJ)
|
||||
}
|
||||
|
||||
func invokeTwoArgsWithNullCheck() -> Any {
|
||||
return methodWithTwoNotnullParameters(OBJ, OBJ)
|
||||
}
|
||||
|
||||
func invokeTwoArgsWithoutNullCheck() -> Any {
|
||||
return privateMethodWithTwoNotnullParameters(OBJ, OBJ)
|
||||
}
|
||||
|
||||
func invokeEightArgsWithNullCheck() -> Any {
|
||||
return methodWithEightNotnullParameters(OBJ, OBJ, OBJ, OBJ, OBJ, OBJ, OBJ, OBJ)
|
||||
}
|
||||
|
||||
func invokeEightArgsWithoutNullCheck() -> Any {
|
||||
return privateMethodWithEightNotnullParameters(OBJ, OBJ, OBJ, OBJ, OBJ, OBJ, OBJ, OBJ)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class PrimeListBenchmark {
|
||||
private var primes: [Int] = []
|
||||
|
||||
func calcDirect() {
|
||||
primes = []
|
||||
primes.append(2)
|
||||
var i = 3
|
||||
while (i <= Constants.BENCHMARK_SIZE) {
|
||||
var simple = true
|
||||
for prime in primes {
|
||||
if (prime * prime > i) {
|
||||
break
|
||||
}
|
||||
if (i % prime == 0) {
|
||||
simple = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if (simple) {
|
||||
primes.append(i)
|
||||
}
|
||||
i += 2
|
||||
}
|
||||
}
|
||||
|
||||
func calcEratosthenes() {
|
||||
primes = []
|
||||
primes.append(contentsOf: 2...Constants.BENCHMARK_SIZE)
|
||||
var i = 0
|
||||
while (i < primes.count) {
|
||||
let divisor = primes[i]
|
||||
primes.removeAll(where: { $0 > divisor && $0 % divisor == 0 })
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class StringBenchmark {
|
||||
private var _data: [String]? = nil
|
||||
var data: [String] {
|
||||
get {
|
||||
return _data!
|
||||
}
|
||||
}
|
||||
var csv: String = ""
|
||||
|
||||
init() {
|
||||
var list: [String] = []
|
||||
list.reserveCapacity(Constants.BENCHMARK_SIZE)
|
||||
for n in stringValues(Constants.BENCHMARK_SIZE) {
|
||||
list.append(n)
|
||||
}
|
||||
_data = list
|
||||
csv = ""
|
||||
for _ in 1...Constants.BENCHMARK_SIZE-1 {
|
||||
let elem = Double.random(in: 0.0..<100.0)
|
||||
csv += String(elem)
|
||||
csv += ","
|
||||
}
|
||||
csv += String(0.0)
|
||||
}
|
||||
|
||||
|
||||
func stringConcat() -> String? {
|
||||
var string: String = ""
|
||||
for it in data {
|
||||
string += it
|
||||
}
|
||||
return string
|
||||
}
|
||||
|
||||
func stringConcatNullable() -> String? {
|
||||
var string: String? = ""
|
||||
for it in data {
|
||||
string? += it
|
||||
}
|
||||
return string
|
||||
}
|
||||
|
||||
func stringBuilderConcat() -> String {
|
||||
var string: String = ""
|
||||
for it in data {
|
||||
string += it
|
||||
}
|
||||
return string
|
||||
}
|
||||
|
||||
func stringBuilderConcatNullable() -> String {
|
||||
var string: String? = ""
|
||||
for it in data {
|
||||
string? += it
|
||||
}
|
||||
return string!
|
||||
}
|
||||
|
||||
func summarizeSplittedCsv() -> Double {
|
||||
let fields = csv.split(separator: ",")
|
||||
var sum = 0.0
|
||||
for field in fields {
|
||||
sum += Double(field) ?? 0.0
|
||||
}
|
||||
return sum
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,558 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
struct ConstParams {
|
||||
static let SPARSE_SWITCH_CASES = [11, 29, 47, 71, 103,
|
||||
149, 175, 227, 263, 307,
|
||||
361, 487, 563, 617, 677,
|
||||
751, 823, 883, 967, 1031]
|
||||
|
||||
static let V1 = 1
|
||||
static let V2 = 2
|
||||
static let V3 = 3
|
||||
static let V4 = 4
|
||||
static let V5 = 5
|
||||
static let V6 = 6
|
||||
static let V7 = 7
|
||||
static let V8 = 8
|
||||
static let V9 = 9
|
||||
static let V10 = 10
|
||||
static let V11 = 11
|
||||
static let V12 = 12
|
||||
static let V13 = 13
|
||||
static let V14 = 14
|
||||
static let V15 = 15
|
||||
static let V16 = 16
|
||||
static let V17 = 17
|
||||
static let V18 = 18
|
||||
static let V19 = 19
|
||||
static let V20 = 20
|
||||
static var VV1 = 1
|
||||
static var VV2 = 2
|
||||
static var VV3 = 3
|
||||
static var VV4 = 4
|
||||
static var VV5 = 5
|
||||
static var VV6 = 6
|
||||
static var VV7 = 7
|
||||
static var VV8 = 8
|
||||
static var VV9 = 9
|
||||
static var VV10 = 10
|
||||
static var VV11 = 11
|
||||
static var VV12 = 12
|
||||
static var VV13 = 13
|
||||
static var VV14 = 14
|
||||
static var VV15 = 15
|
||||
static var VV16 = 16
|
||||
static var VV17 = 17
|
||||
static var VV18 = 18
|
||||
static var VV19 = 19
|
||||
static var VV20 = 20
|
||||
}
|
||||
|
||||
|
||||
struct NumbersObj {
|
||||
static let shared = NumbersObj()
|
||||
|
||||
private init() { }
|
||||
|
||||
let V1 = 1
|
||||
let V2 = 2
|
||||
let V3 = 3
|
||||
let V4 = 4
|
||||
let V5 = 5
|
||||
let V6 = 6
|
||||
let V7 = 7
|
||||
let V8 = 8
|
||||
let V9 = 9
|
||||
let V10 = 10
|
||||
let V11 = 11
|
||||
let V12 = 12
|
||||
let V13 = 13
|
||||
let V14 = 14
|
||||
let V15 = 15
|
||||
let V16 = 16
|
||||
let V17 = 17
|
||||
let V18 = 18
|
||||
let V19 = 19
|
||||
let V20 = 20
|
||||
}
|
||||
|
||||
class SwitchBenchmark {
|
||||
func sparseIntSwitch(_ u : Int) -> Int {
|
||||
var t : Int
|
||||
switch (u) {
|
||||
case 11:
|
||||
t = 1
|
||||
case 29:
|
||||
t = 2
|
||||
case 47:
|
||||
t = 3
|
||||
case 71:
|
||||
t = 4
|
||||
case 103:
|
||||
t = 5
|
||||
case 149:
|
||||
t = 6
|
||||
case 175:
|
||||
t = 7
|
||||
case 227:
|
||||
t = 1
|
||||
case 263:
|
||||
t = 9
|
||||
case 307:
|
||||
t = 1
|
||||
case 361:
|
||||
t = 2
|
||||
case 487:
|
||||
t = 3
|
||||
case 563:
|
||||
t = 4
|
||||
case 617:
|
||||
t = 4
|
||||
case 677:
|
||||
t = 4
|
||||
case 751:
|
||||
t = 435
|
||||
case 823:
|
||||
t = 31
|
||||
case 883:
|
||||
t = 1
|
||||
case 967:
|
||||
t = 1
|
||||
case 1031:
|
||||
t = 1
|
||||
case 20:
|
||||
t = 1
|
||||
default:
|
||||
t = 5
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func denseIntSwitch(_ u : Int) -> Int {
|
||||
var t : Int
|
||||
switch (u) {
|
||||
case 1:
|
||||
t = 1
|
||||
case -1:
|
||||
t = 2
|
||||
case 2:
|
||||
t = 3
|
||||
case 3:
|
||||
t = 4
|
||||
case 4:
|
||||
t = 5
|
||||
case 5:
|
||||
t = 6
|
||||
case 6:
|
||||
t = 7
|
||||
case 7:
|
||||
t = 1
|
||||
case 8:
|
||||
t = 9
|
||||
case 9:
|
||||
t = 1
|
||||
case 10:
|
||||
t = 2
|
||||
case 11:
|
||||
t = 3
|
||||
case 12:
|
||||
t = 4
|
||||
case 13:
|
||||
t = 4
|
||||
case 14:
|
||||
t = 4
|
||||
case 15:
|
||||
t = 435
|
||||
case 16:
|
||||
t = 31
|
||||
case 17:
|
||||
t = 1
|
||||
case 18:
|
||||
t = 1
|
||||
case 19:
|
||||
t = 1
|
||||
case 20:
|
||||
t = 1
|
||||
default:
|
||||
t = 5
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func constSwitch(_ u : Int) -> Int {
|
||||
var t : Int
|
||||
switch (u) {
|
||||
case ConstParams.V1:
|
||||
t = 1
|
||||
case ConstParams.V2:
|
||||
t = 3
|
||||
case ConstParams.V3:
|
||||
t = 4
|
||||
case ConstParams.V4:
|
||||
t = 5
|
||||
case ConstParams.V5:
|
||||
t = 6
|
||||
case ConstParams.V6:
|
||||
t = 7
|
||||
case ConstParams.V7:
|
||||
t = 1
|
||||
case ConstParams.V8:
|
||||
t = 9
|
||||
case ConstParams.V9:
|
||||
t = 1
|
||||
case ConstParams.V10:
|
||||
t = 2
|
||||
case ConstParams.V11:
|
||||
t = 3
|
||||
case ConstParams.V12:
|
||||
t = 4
|
||||
case ConstParams.V13:
|
||||
t = 4
|
||||
case ConstParams.V14:
|
||||
t = 4
|
||||
case ConstParams.V15:
|
||||
t = 435
|
||||
case ConstParams.V16:
|
||||
t = 31
|
||||
case ConstParams.V17:
|
||||
t = 1
|
||||
case ConstParams.V18:
|
||||
t = 1
|
||||
case ConstParams.V19:
|
||||
t = 1
|
||||
case ConstParams.V20:
|
||||
t = 1
|
||||
default:
|
||||
t = 5
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func objConstSwitch(_ u : Int) -> Int {
|
||||
var t : Int
|
||||
switch (u) {
|
||||
case NumbersObj.shared.V1:
|
||||
t = 1
|
||||
case NumbersObj.shared.V2:
|
||||
t = 3
|
||||
case NumbersObj.shared.V3:
|
||||
t = 4
|
||||
case NumbersObj.shared.V4:
|
||||
t = 5
|
||||
case NumbersObj.shared.V5:
|
||||
t = 6
|
||||
case NumbersObj.shared.V6:
|
||||
t = 7
|
||||
case NumbersObj.shared.V7:
|
||||
t = 1
|
||||
case NumbersObj.shared.V8:
|
||||
t = 9
|
||||
case NumbersObj.shared.V9:
|
||||
t = 1
|
||||
case NumbersObj.shared.V10:
|
||||
t = 2
|
||||
case NumbersObj.shared.V11:
|
||||
t = 3
|
||||
case NumbersObj.shared.V12:
|
||||
t = 4
|
||||
case NumbersObj.shared.V13:
|
||||
t = 4
|
||||
case NumbersObj.shared.V14:
|
||||
t = 4
|
||||
case NumbersObj.shared.V15:
|
||||
t = 435
|
||||
case NumbersObj.shared.V16:
|
||||
t = 31
|
||||
case NumbersObj.shared.V17:
|
||||
t = 1
|
||||
case NumbersObj.shared.V18:
|
||||
t = 1
|
||||
case NumbersObj.shared.V19:
|
||||
t = 1
|
||||
case NumbersObj.shared.V20:
|
||||
t = 1
|
||||
default:
|
||||
t = 5
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func varSwitch(_ u : Int) -> Int {
|
||||
var t : Int
|
||||
switch (u) {
|
||||
case ConstParams.VV1:
|
||||
t = 1
|
||||
case ConstParams.VV2:
|
||||
t = 3
|
||||
case ConstParams.VV3:
|
||||
t = 4
|
||||
case ConstParams.VV4:
|
||||
t = 5
|
||||
case ConstParams.VV5:
|
||||
t = 6
|
||||
case ConstParams.VV6:
|
||||
t = 7
|
||||
case ConstParams.VV7:
|
||||
t = 1
|
||||
case ConstParams.VV8:
|
||||
t = 9
|
||||
case ConstParams.VV9:
|
||||
t = 1
|
||||
case ConstParams.VV10:
|
||||
t = 2
|
||||
case ConstParams.VV11:
|
||||
t = 3
|
||||
case ConstParams.VV12:
|
||||
t = 4
|
||||
case ConstParams.VV13:
|
||||
t = 4
|
||||
case ConstParams.VV14:
|
||||
t = 4
|
||||
case ConstParams.VV15:
|
||||
t = 435
|
||||
case ConstParams.VV16:
|
||||
t = 31
|
||||
case ConstParams.VV17:
|
||||
t = 1
|
||||
case ConstParams.VV18:
|
||||
t = 1
|
||||
case ConstParams.VV19:
|
||||
t = 1
|
||||
case ConstParams.VV20:
|
||||
t = 1
|
||||
default:
|
||||
t = 5
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
private func stringSwitch(_ s: String) -> Int {
|
||||
switch (s) {
|
||||
case "ABCDEFG1": return 1
|
||||
case "ABCDEFG2": return 2
|
||||
case "ABCDEFG2": return 3
|
||||
case "ABCDEFG3": return 4
|
||||
case "ABCDEFG4": return 5
|
||||
case "ABCDEFG5": return 6
|
||||
case "ABCDEFG6": return 7
|
||||
case "ABCDEFG7": return 8
|
||||
case "ABCDEFG8": return 9
|
||||
case "ABCDEFG9": return 10
|
||||
case "ABCDEFG10": return 11
|
||||
case "ABCDEFG11": return 12
|
||||
case "ABCDEFG12": return 1
|
||||
case "ABCDEFG13": return 2
|
||||
case "ABCDEFG14": return 3
|
||||
case "ABCDEFG15": return 4
|
||||
case "ABCDEFG16": return 5
|
||||
case "ABCDEFG17": return 6
|
||||
case "ABCDEFG18": return 7
|
||||
case "ABCDEFG19": return 8
|
||||
case "ABCDEFG20": return 9
|
||||
default: return -1
|
||||
}
|
||||
}
|
||||
|
||||
var denseIntData: [Int]
|
||||
var sparseIntData: [Int]
|
||||
|
||||
func testSparseIntSwitch() {
|
||||
for i in sparseIntData {
|
||||
Blackhole.consume(sparseIntSwitch(i))
|
||||
}
|
||||
}
|
||||
|
||||
func testDenseIntSwitch() {
|
||||
for i in denseIntData {
|
||||
Blackhole.consume(denseIntSwitch(i))
|
||||
}
|
||||
}
|
||||
|
||||
func testConstSwitch() {
|
||||
for i in denseIntData {
|
||||
Blackhole.consume(constSwitch(i))
|
||||
}
|
||||
}
|
||||
|
||||
func testObjConstSwitch() {
|
||||
for i in denseIntData {
|
||||
Blackhole.consume(objConstSwitch(i))
|
||||
}
|
||||
}
|
||||
|
||||
func testVarSwitch() {
|
||||
for i in denseIntData {
|
||||
Blackhole.consume(varSwitch(i))
|
||||
}
|
||||
}
|
||||
|
||||
var data: [String] = []
|
||||
|
||||
func testStringsSwitch() {
|
||||
let n = data.count
|
||||
for s in data {
|
||||
Blackhole.consume(stringSwitch(s))
|
||||
}
|
||||
}
|
||||
|
||||
enum MyEnum: CaseIterable {
|
||||
case 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 func enumSwitch(_ x: MyEnum) -> Int {
|
||||
switch (x) {
|
||||
case MyEnum.ITEM5: return 1
|
||||
case MyEnum.ITEM10: return 2
|
||||
case MyEnum.ITEM15: return 3
|
||||
case MyEnum.ITEM20: return 4
|
||||
case MyEnum.ITEM25: return 5
|
||||
case MyEnum.ITEM30: return 6
|
||||
case MyEnum.ITEM35: return 7
|
||||
case MyEnum.ITEM40: return 8
|
||||
case MyEnum.ITEM45: return 9
|
||||
case MyEnum.ITEM50: return 10
|
||||
case MyEnum.ITEM55: return 11
|
||||
case MyEnum.ITEM60: return 12
|
||||
case MyEnum.ITEM65: return 13
|
||||
case MyEnum.ITEM70: return 14
|
||||
case MyEnum.ITEM75: return 15
|
||||
case MyEnum.ITEM80: return 16
|
||||
case MyEnum.ITEM85: return 17
|
||||
case MyEnum.ITEM90: return 18
|
||||
case MyEnum.ITEM95: return 19
|
||||
case MyEnum.ITEM100: return 20
|
||||
default: return -1
|
||||
}
|
||||
}
|
||||
|
||||
private func denseEnumSwitch(x: MyEnum) -> Int {
|
||||
switch (x) {
|
||||
case MyEnum.ITEM1: return 1
|
||||
case MyEnum.ITEM2: return 2
|
||||
case MyEnum.ITEM3: return 3
|
||||
case MyEnum.ITEM4: return 4
|
||||
case MyEnum.ITEM5: return 5
|
||||
case MyEnum.ITEM6: return 6
|
||||
case MyEnum.ITEM7: return 7
|
||||
case MyEnum.ITEM8: return 8
|
||||
case MyEnum.ITEM9: return 9
|
||||
case MyEnum.ITEM10: return 10
|
||||
case MyEnum.ITEM11: return 11
|
||||
case MyEnum.ITEM12: return 12
|
||||
case MyEnum.ITEM13: return 13
|
||||
case MyEnum.ITEM14: return 14
|
||||
case MyEnum.ITEM15: return 15
|
||||
case MyEnum.ITEM16: return 16
|
||||
case MyEnum.ITEM17: return 17
|
||||
case MyEnum.ITEM18: return 18
|
||||
case MyEnum.ITEM19: return 19
|
||||
case MyEnum.ITEM20: return 20
|
||||
default: return -1
|
||||
}
|
||||
}
|
||||
|
||||
var enumData : [MyEnum]
|
||||
var denseEnumData : [MyEnum]
|
||||
|
||||
func testEnumsSwitch() {
|
||||
let n = enumData.count - 1
|
||||
let data = enumData
|
||||
for i in 0...n {
|
||||
Blackhole.consume(enumSwitch(data[i]))
|
||||
}
|
||||
}
|
||||
|
||||
func testDenseEnumsSwitch() {
|
||||
let n = denseEnumData.count - 1
|
||||
let data = denseEnumData
|
||||
for i in 0...n {
|
||||
Blackhole.consume(denseEnumSwitch(x: data[i]))
|
||||
}
|
||||
}
|
||||
|
||||
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 {}
|
||||
}
|
||||
|
||||
var sealedClassData: [MySealedClass]
|
||||
|
||||
init() {
|
||||
data = []
|
||||
for _ in 0..<Constants.BENCHMARK_SIZE {
|
||||
data.append("ABCDEFG\(Int.random(in: 0...22))")
|
||||
}
|
||||
enumData = []
|
||||
for i in 0..<Constants.BENCHMARK_SIZE {
|
||||
enumData.append(MyEnum.allCases[i % MyEnum.allCases.count])
|
||||
}
|
||||
denseEnumData = []
|
||||
for i in 0..<Constants.BENCHMARK_SIZE {
|
||||
denseEnumData.append(MyEnum.allCases[i % 20])
|
||||
}
|
||||
denseIntData = []
|
||||
for _ in 0..<Constants.BENCHMARK_SIZE {
|
||||
denseIntData.append(Int.random(in: 0...25) - 1)
|
||||
}
|
||||
sparseIntData = []
|
||||
for _ in 0..<Constants.BENCHMARK_SIZE {
|
||||
sparseIntData.append(ConstParams.SPARSE_SWITCH_CASES[Int.random(in: 0..<20)])
|
||||
}
|
||||
sealedClassData = []
|
||||
for _ in 0..<Constants.BENCHMARK_SIZE {
|
||||
switch(Int.random(in: 0..<10)) {
|
||||
case 0: sealedClassData.append(MySealedClass.MySealedClass1())
|
||||
case 1: sealedClassData.append(MySealedClass.MySealedClass2())
|
||||
case 2: sealedClassData.append(MySealedClass.MySealedClass3())
|
||||
case 3: sealedClassData.append(MySealedClass.MySealedClass4())
|
||||
case 4: sealedClassData.append(MySealedClass.MySealedClass5())
|
||||
case 5: sealedClassData.append(MySealedClass.MySealedClass6())
|
||||
case 6: sealedClassData.append(MySealedClass.MySealedClass7())
|
||||
case 7: sealedClassData.append(MySealedClass.MySealedClass8())
|
||||
case 8: sealedClassData.append(MySealedClass.MySealedClass9())
|
||||
case 9: sealedClassData.append(MySealedClass.MySealedClass10())
|
||||
default: print("Exception.illigalStateException")
|
||||
}
|
||||
}
|
||||
}
|
||||
enum Exception: Error {
|
||||
case illigalStateException
|
||||
}
|
||||
|
||||
private func sealedWhenSwitch(_ x: MySealedClass) -> Int {
|
||||
switch (x) {
|
||||
case is MySealedClass.MySealedClass1: return 1
|
||||
case is MySealedClass.MySealedClass2: return 2
|
||||
case is MySealedClass.MySealedClass3: return 3
|
||||
case is MySealedClass.MySealedClass4: return 4
|
||||
case is MySealedClass.MySealedClass5: return 5
|
||||
case is MySealedClass.MySealedClass6: return 6
|
||||
case is MySealedClass.MySealedClass7: return 7
|
||||
case is MySealedClass.MySealedClass8: return 8
|
||||
case is MySealedClass.MySealedClass9: return 9
|
||||
case is MySealedClass.MySealedClass10: return 10
|
||||
default:
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
func testSealedWhenSwitch() {
|
||||
let n = sealedClassData.count - 1
|
||||
for i in 0...n {
|
||||
Blackhole.consume(sealedWhenSwitch(sealedClassData[i]))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class Blackhole {
|
||||
@inline(never)
|
||||
static var flag: Bool = false
|
||||
@inline(never)
|
||||
static func consume<T: Any>(_ value: T) {
|
||||
if (flag) {
|
||||
print(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Constants {
|
||||
static let BENCHMARK_SIZE = 10000
|
||||
static let RUNS = 1_000_000
|
||||
static var globalAddendum = 0
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
class WithIndiciesBenchmark {
|
||||
private var _data: [Value]? = nil
|
||||
var data: [Value] {
|
||||
get {
|
||||
return _data!
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
var list: [Value] = []
|
||||
for n in classValues(Constants.BENCHMARK_SIZE) {
|
||||
list.append(n)
|
||||
}
|
||||
_data = list
|
||||
}
|
||||
|
||||
func withIndicies() {
|
||||
for (index, value) in data.lazy.enumerated() {
|
||||
if (filterLoad(value)) {
|
||||
Blackhole.consume(index)
|
||||
Blackhole.consume(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func withIndiciesManual() {
|
||||
var index = 0
|
||||
for value in data {
|
||||
if (filterLoad(value)) {
|
||||
Blackhole.consume(index)
|
||||
Blackhole.consume(value)
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,477 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
import benchmark
|
||||
|
||||
var runner = BenchmarksRunner()
|
||||
let args = KotlinArray<NSString>(size: Int32(CommandLine.arguments.count - 1), init: {index in
|
||||
CommandLine.arguments[Int(truncating: index) + 1] as NSString
|
||||
})
|
||||
|
||||
let companion = BenchmarkEntryWithInit.Companion()
|
||||
|
||||
var swiftLauncher = SwiftLauncher()
|
||||
|
||||
extension SwiftLauncher {
|
||||
static func abstractMethodBenchmark(_ instance: Any) -> AbstractMethodBenchmark {
|
||||
return instance as! AbstractMethodBenchmark
|
||||
}
|
||||
|
||||
static func classArrayBenchmark(_ instance: Any) -> ClassArrayBenchmark {
|
||||
return instance as! ClassArrayBenchmark
|
||||
}
|
||||
|
||||
static func classListBenchmark(_ instance: Any) -> ClassListBenchmark {
|
||||
return instance as! ClassListBenchmark
|
||||
}
|
||||
|
||||
static func classBaselineBenchmark(_ instance: Any) -> ClassBaselineBenchmark {
|
||||
return instance as! ClassBaselineBenchmark
|
||||
}
|
||||
|
||||
static func classStreamBenchmark(_ instance: Any) -> ClassStreamBenchmark {
|
||||
return instance as! ClassStreamBenchmark
|
||||
}
|
||||
|
||||
static func companionObjectBenchmark(_ instance: Any) -> CompanionObjectBenchmark {
|
||||
return instance as! CompanionObjectBenchmark
|
||||
}
|
||||
|
||||
static func defaultArgumentBenchmark(_ instance: Any) -> DefaultArgumentBenchmark {
|
||||
return instance as! DefaultArgumentBenchmark
|
||||
}
|
||||
|
||||
static func elvisBenchmark(_ instance: Any) -> ElvisBenchmark {
|
||||
return instance as! ElvisBenchmark
|
||||
}
|
||||
|
||||
static func eulerBenchmark(_ instance: Any) -> EulerBenchmark {
|
||||
return instance as! EulerBenchmark
|
||||
}
|
||||
|
||||
static func fibonacciBenchmark(_ instance: Any) -> FibonacciBenchmark {
|
||||
return instance as! FibonacciBenchmark
|
||||
}
|
||||
|
||||
static func forLoopsBenchmark(_ instance: Any) -> ForLoopsBenchmark {
|
||||
return instance as! ForLoopsBenchmark
|
||||
}
|
||||
|
||||
static func inlineBenchmark(_ instance: Any) -> InlineBenchmark {
|
||||
return instance as! InlineBenchmark
|
||||
}
|
||||
|
||||
static func intArrayBenchmark(_ instance: Any) -> IntArrayBenchmark {
|
||||
return instance as! IntArrayBenchmark
|
||||
}
|
||||
|
||||
static func intBaselineBenchmark(_ instance: Any) -> IntBaselineBenchmark {
|
||||
return instance as! IntBaselineBenchmark
|
||||
}
|
||||
|
||||
static func intStreamBenchmark(_ instance: Any) -> IntStreamBenchmark {
|
||||
return instance as! IntStreamBenchmark
|
||||
}
|
||||
|
||||
static func lambdaBenchmark(_ instance: Any) -> LambdaBenchmark {
|
||||
return instance as! LambdaBenchmark
|
||||
}
|
||||
|
||||
static func loopBenchmark(_ instance: Any) -> LoopBenchmark {
|
||||
return instance as! LoopBenchmark
|
||||
}
|
||||
|
||||
static func matrixMapBenchmark(_ instance: Any) -> MatrixMapBenchmark {
|
||||
return instance as! MatrixMapBenchmark
|
||||
}
|
||||
|
||||
static func parameterNotNullAssertionBenchmark(_ instance: Any) -> ParameterNotNullAssertionBenchmark {
|
||||
return instance as! ParameterNotNullAssertionBenchmark
|
||||
}
|
||||
|
||||
static func primeListBenchmark(_ instance: Any) -> PrimeListBenchmark {
|
||||
return instance as! PrimeListBenchmark
|
||||
}
|
||||
|
||||
static func stringBenchmark(_ instance: Any) -> StringBenchmark {
|
||||
return instance as! StringBenchmark
|
||||
}
|
||||
|
||||
static func switchBenchmark(_ instance: Any) -> SwitchBenchmark {
|
||||
return instance as! SwitchBenchmark
|
||||
}
|
||||
|
||||
static func withIndiciesBenchmark(_ instance: Any) -> WithIndiciesBenchmark {
|
||||
return instance as! WithIndiciesBenchmark
|
||||
}
|
||||
|
||||
static func callsBenchmarks(_ instance: Any) -> CallsBenchmarks {
|
||||
return instance as! CallsBenchmarks
|
||||
}
|
||||
|
||||
static func coordinatesSolverBenchmark(_ instance: Any) -> CoordinatesSolverBenchmark {
|
||||
return instance as! CoordinatesSolverBenchmark
|
||||
}
|
||||
|
||||
static func graphSolverBenchmark(_ instance: Any) -> GraphSolverBenchmark {
|
||||
return instance as! GraphSolverBenchmark
|
||||
}
|
||||
|
||||
static func castsBenchmark(_ instance: Any) -> CastsBenchmark {
|
||||
return instance as! CastsBenchmark
|
||||
}
|
||||
}
|
||||
|
||||
swiftLauncher.add(name: "AbstractMethod.sortStrings", benchmark: companion.create(ctor: { return AbstractMethodBenchmark() },
|
||||
lambda: { SwiftLauncher.abstractMethodBenchmark($0).sortStrings() }))
|
||||
swiftLauncher.add(name: "AbstractMethod.sortStringsWithComparator", benchmark: companion.create(ctor: { return AbstractMethodBenchmark() },
|
||||
lambda: { SwiftLauncher.abstractMethodBenchmark($0).sortStringsWithComparator() }))
|
||||
|
||||
swiftLauncher.add(name: "ClassArray.copy", benchmark: companion.create(ctor: { return ClassArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.classArrayBenchmark($0).copy() }))
|
||||
swiftLauncher.add(name: "ClassArray.copyManual", benchmark: companion.create(ctor: { return ClassArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.classArrayBenchmark($0).copyManual() }))
|
||||
swiftLauncher.add(name: "ClassArray.filterAndCount", benchmark: companion.create(ctor: { return ClassArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.classArrayBenchmark($0).filterAndCount() }))
|
||||
swiftLauncher.add(name: "ClassArray.filterAndMap", benchmark: companion.create(ctor: { return ClassArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.classArrayBenchmark($0).filterAndMap() }))
|
||||
swiftLauncher.add(name: "ClassArray.filterAndMapManual", benchmark: companion.create(ctor: { return ClassArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.classArrayBenchmark($0).filterAndMapManual() }))
|
||||
swiftLauncher.add(name: "ClassArray.filter", benchmark: companion.create(ctor: { return ClassArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.classArrayBenchmark($0).filter() }))
|
||||
swiftLauncher.add(name: "ClassArray.filterManual", benchmark: companion.create(ctor: { return ClassArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.classArrayBenchmark($0).filterManual() }))
|
||||
swiftLauncher.add(name: "ClassArray.countFilteredManual", benchmark: companion.create(ctor: { return ClassArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.classArrayBenchmark($0).countFilteredManual() }))
|
||||
swiftLauncher.add(name: "ClassArray.countFiltered", benchmark: companion.create(ctor: { return ClassArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.classArrayBenchmark($0).countFiltered() }))
|
||||
swiftLauncher.add(name: "ClassArray.countFilteredLocal", benchmark: companion.create(ctor: { return ClassArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.classArrayBenchmark($0).countFilteredLocal() }))
|
||||
|
||||
swiftLauncher.add(name: "ClassBaseline.consume", benchmark: companion.create(ctor: { return ClassBaselineBenchmark() },
|
||||
lambda: { SwiftLauncher.classBaselineBenchmark($0).consume() }))
|
||||
swiftLauncher.add(name: "ClassBaseline.consumeField", benchmark: companion.create(ctor: { return ClassBaselineBenchmark() },
|
||||
lambda: { SwiftLauncher.classBaselineBenchmark($0).consumeField() }))
|
||||
swiftLauncher.add(name: "ClassBaseline.allocateList", benchmark: companion.create(ctor: { return ClassBaselineBenchmark() },
|
||||
lambda: { SwiftLauncher.classBaselineBenchmark($0).allocateList() }))
|
||||
swiftLauncher.add(name: "ClassBaseline.allocateArray", benchmark: companion.create(ctor: { return ClassBaselineBenchmark() },
|
||||
lambda: { SwiftLauncher.classBaselineBenchmark($0).allocateArray() }))
|
||||
swiftLauncher.add(name: "ClassBaseline.allocateListAndFill", benchmark: companion.create(ctor: { return ClassBaselineBenchmark() },
|
||||
lambda: { SwiftLauncher.classBaselineBenchmark($0).allocateListAndFill() }))
|
||||
swiftLauncher.add(name: "ClassBaseline.allocateListAndWrite", benchmark: companion.create(ctor: { return ClassBaselineBenchmark() },
|
||||
lambda: { SwiftLauncher.classBaselineBenchmark($0).allocateListAndWrite() }))
|
||||
swiftLauncher.add(name: "ClassBaseline.allocateArrayAndFill", benchmark: companion.create(ctor: { return ClassBaselineBenchmark() },
|
||||
lambda: { SwiftLauncher.classBaselineBenchmark($0).allocateArrayAndFill() }))
|
||||
|
||||
swiftLauncher.add(name: "ClassList.filterAndCountWithLambda", benchmark: companion.create(ctor: { return ClassListBenchmark() },
|
||||
lambda: { SwiftLauncher.classListBenchmark($0).filterAndCountWithLambda() }))
|
||||
swiftLauncher.add(name: "ClassList.filterWithLambda", benchmark: companion.create(ctor: { return ClassListBenchmark() },
|
||||
lambda: { SwiftLauncher.classListBenchmark($0).filterWithLambda() }))
|
||||
swiftLauncher.add(name: "ClassList.mapWithLambda", benchmark: companion.create(ctor: { return ClassListBenchmark() },
|
||||
lambda: { SwiftLauncher.classListBenchmark($0).mapWithLambda() }))
|
||||
swiftLauncher.add(name: "ClassList.countWithLambda", benchmark: companion.create(ctor: { return ClassListBenchmark() },
|
||||
lambda: { SwiftLauncher.classListBenchmark($0).countWithLambda() }))
|
||||
swiftLauncher.add(name: "ClassList.filterAndMapWithLambda", benchmark: companion.create(ctor: { return ClassListBenchmark() },
|
||||
lambda: { SwiftLauncher.classListBenchmark($0).filterAndMapWithLambda() }))
|
||||
swiftLauncher.add(name: "ClassList.filterAndMapWithLambdaAsSequence", benchmark: companion.create(ctor: { return ClassListBenchmark() },
|
||||
lambda: { SwiftLauncher.classListBenchmark($0).filterAndMapWithLambdaAsSequence() }))
|
||||
swiftLauncher.add(name: "ClassList.reduce", benchmark: companion.create(ctor: { return ClassListBenchmark() },
|
||||
lambda: { SwiftLauncher.classListBenchmark($0).reduce() }))
|
||||
|
||||
swiftLauncher.add(name: "ClassStream.copy", benchmark: companion.create(ctor: { return ClassStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.classStreamBenchmark($0).copy() }))
|
||||
swiftLauncher.add(name: "ClassStream.copyManual", benchmark: companion.create(ctor: { return ClassStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.classStreamBenchmark($0).copyManual() }))
|
||||
swiftLauncher.add(name: "ClassStream.filterAndCount", benchmark: companion.create(ctor: { return ClassStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.classStreamBenchmark($0).filterAndCount() }))
|
||||
swiftLauncher.add(name: "ClassStream.filterAndMap", benchmark: companion.create(ctor: { return ClassStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.classStreamBenchmark($0).filterAndMap() }))
|
||||
swiftLauncher.add(name: "ClassStream.filterAndMapManual", benchmark: companion.create(ctor: { return ClassStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.classStreamBenchmark($0).filterAndMapManual() }))
|
||||
swiftLauncher.add(name: "ClassStream.filter", benchmark: companion.create(ctor: { return ClassStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.classStreamBenchmark($0).filter() }))
|
||||
swiftLauncher.add(name: "ClassStream.filterManual", benchmark: companion.create(ctor: { return ClassStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.classStreamBenchmark($0).filterManual() }))
|
||||
swiftLauncher.add(name: "ClassStream.countFilteredManual", benchmark: companion.create(ctor: { return ClassStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.classStreamBenchmark($0).countFilteredManual() }))
|
||||
swiftLauncher.add(name: "ClassStream.reduce", benchmark: companion.create(ctor: { return ClassStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.classStreamBenchmark($0).reduce() }))
|
||||
|
||||
swiftLauncher.add(name: "CompanionObject.invokeRegularFunction", benchmark: companion.create(ctor: { return CompanionObjectBenchmark() },
|
||||
lambda: { SwiftLauncher.companionObjectBenchmark($0).invokeRegularFunction() }))
|
||||
|
||||
swiftLauncher.add(name: "DefaultArgument.testOneOfTwo", benchmark: companion.create(ctor: { return DefaultArgumentBenchmark() },
|
||||
lambda: { SwiftLauncher.defaultArgumentBenchmark($0).testOneOfTwo() }))
|
||||
swiftLauncher.add(name: "DefaultArgument.testTwoOfTwo", benchmark: companion.create(ctor: { return DefaultArgumentBenchmark() },
|
||||
lambda: { SwiftLauncher.defaultArgumentBenchmark($0).testTwoOfTwo() }))
|
||||
swiftLauncher.add(name: "DefaultArgument.testOneOfFour", benchmark: companion.create(ctor: { return DefaultArgumentBenchmark() },
|
||||
lambda: { SwiftLauncher.defaultArgumentBenchmark($0).testOneOfFour() }))
|
||||
swiftLauncher.add(name: "DefaultArgument.testFourOfFour", benchmark: companion.create(ctor: { return DefaultArgumentBenchmark() },
|
||||
lambda: { SwiftLauncher.defaultArgumentBenchmark($0).testFourOfFour() }))
|
||||
swiftLauncher.add(name: "DefaultArgument.testOneOfEight", benchmark: companion.create(ctor: { return DefaultArgumentBenchmark() },
|
||||
lambda: { SwiftLauncher.defaultArgumentBenchmark($0).testOneOfEight() }))
|
||||
swiftLauncher.add(name: "DefaultArgument.testEightOfEight", benchmark: companion.create(ctor: { return DefaultArgumentBenchmark() },
|
||||
lambda: { SwiftLauncher.defaultArgumentBenchmark($0).testEightOfEight() }))
|
||||
|
||||
swiftLauncher.add(name: "Elvis.testElvis", benchmark: companion.create(ctor: { return ElvisBenchmark() },
|
||||
lambda: { SwiftLauncher.elvisBenchmark($0).testElvis() }))
|
||||
|
||||
swiftLauncher.add(name: "Euler.problem1bySequence", benchmark: companion.create(ctor: { return EulerBenchmark() },
|
||||
lambda: { SwiftLauncher.eulerBenchmark($0).problem1bySequence() }))
|
||||
swiftLauncher.add(name: "Euler.problem1", benchmark: companion.create(ctor: { return EulerBenchmark() },
|
||||
lambda: { SwiftLauncher.eulerBenchmark($0).problem1() }))
|
||||
swiftLauncher.add(name: "Euler.problem2", benchmark: companion.create(ctor: { return EulerBenchmark() },
|
||||
lambda: { SwiftLauncher.eulerBenchmark($0).problem2() }))
|
||||
swiftLauncher.add(name: "Euler.problem4", benchmark: companion.create(ctor: { return EulerBenchmark() },
|
||||
lambda: { SwiftLauncher.eulerBenchmark($0).problem4() }))
|
||||
swiftLauncher.add(name: "Euler.problem8", benchmark: companion.create(ctor: { return EulerBenchmark() },
|
||||
lambda: { SwiftLauncher.eulerBenchmark($0).problem8() }))
|
||||
swiftLauncher.add(name: "Euler.problem9", benchmark: companion.create(ctor: { return EulerBenchmark() },
|
||||
lambda: { SwiftLauncher.eulerBenchmark($0).problem9() }))
|
||||
swiftLauncher.add(name: "Euler.problem14", benchmark: companion.create(ctor: { return EulerBenchmark() },
|
||||
lambda: { SwiftLauncher.eulerBenchmark($0).problem14() }))
|
||||
swiftLauncher.add(name: "Euler.problem14full", benchmark: companion.create(ctor: { return EulerBenchmark() },
|
||||
lambda: { SwiftLauncher.eulerBenchmark($0).problem14full() }))
|
||||
|
||||
swiftLauncher.add(name: "Fibonacci.calcClassic", benchmark: companion.create(ctor: { return FibonacciBenchmark() },
|
||||
lambda: { SwiftLauncher.fibonacciBenchmark($0).calcClassic() }))
|
||||
swiftLauncher.add(name: "Fibonacci.calc", benchmark: companion.create(ctor: { return FibonacciBenchmark() },
|
||||
lambda: { SwiftLauncher.fibonacciBenchmark($0).calc() }))
|
||||
swiftLauncher.add(name: "Fibonacci.calcWithProgression", benchmark: companion.create(ctor: { return FibonacciBenchmark() },
|
||||
lambda: { SwiftLauncher.fibonacciBenchmark($0).calcWithProgression() }))
|
||||
swiftLauncher.add(name: "Fibonacci.calcSquare", benchmark: companion.create(ctor: { return FibonacciBenchmark() },
|
||||
lambda: { SwiftLauncher.fibonacciBenchmark($0).calcSquare() }))
|
||||
|
||||
swiftLauncher.add(name: "ForLoops.arrayLoop", benchmark: companion.create(ctor: { return ForLoopsBenchmark() },
|
||||
lambda: { SwiftLauncher.forLoopsBenchmark($0).arrayLoop() }))
|
||||
swiftLauncher.add(name: "ForLoops.floatArrayLoop", benchmark: companion.create(ctor: { return ForLoopsBenchmark() },
|
||||
lambda: { SwiftLauncher.forLoopsBenchmark($0).floatArrayLoop() }))
|
||||
swiftLauncher.add(name: "ForLoops.charArrayLoop", benchmark: companion.create(ctor: { return ForLoopsBenchmark() },
|
||||
lambda: { SwiftLauncher.forLoopsBenchmark($0).charArrayLoop() }))
|
||||
swiftLauncher.add(name: "ForLoops.stringLoop", benchmark: companion.create(ctor: { return ForLoopsBenchmark() },
|
||||
lambda: { SwiftLauncher.forLoopsBenchmark($0).stringLoop() }))
|
||||
swiftLauncher.add(name: "ForLoops.arrayIndicesLoop", benchmark: companion.create(ctor: { return ForLoopsBenchmark() },
|
||||
lambda: { SwiftLauncher.forLoopsBenchmark($0).arrayIndicesLoop() }))
|
||||
swiftLauncher.add(name: "ForLoops.floatArrayIndicesLoop", benchmark: companion.create(ctor: { return ForLoopsBenchmark() },
|
||||
lambda: { SwiftLauncher.forLoopsBenchmark($0).floatArrayIndicesLoop() }))
|
||||
swiftLauncher.add(name: "ForLoops.charArrayIndicesLoop", benchmark: companion.create(ctor: { return ForLoopsBenchmark() },
|
||||
lambda: { SwiftLauncher.forLoopsBenchmark($0).charArrayIndicesLoop() }))
|
||||
swiftLauncher.add(name: "ForLoops.stringIndicesLoop", benchmark: companion.create(ctor: { return ForLoopsBenchmark() },
|
||||
lambda: { SwiftLauncher.forLoopsBenchmark($0).stringIndicesLoop() }))
|
||||
|
||||
swiftLauncher.add(name: "Inline.calculate", benchmark: companion.create(ctor: { return InlineBenchmark() },
|
||||
lambda: { SwiftLauncher.inlineBenchmark($0).calculate() }))
|
||||
swiftLauncher.add(name: "Inline.calculateInline", benchmark: companion.create(ctor: { return InlineBenchmark() },
|
||||
lambda: { SwiftLauncher.inlineBenchmark($0).calculateInline() }))
|
||||
swiftLauncher.add(name: "Inline.calculateGeneric", benchmark: companion.create(ctor: { return InlineBenchmark() },
|
||||
lambda: { SwiftLauncher.inlineBenchmark($0).calculateGeneric() }))
|
||||
swiftLauncher.add(name: "Inline.calculateGenericInline", benchmark: companion.create(ctor: { return InlineBenchmark() },
|
||||
lambda: { SwiftLauncher.inlineBenchmark($0).calculateGenericInline() }))
|
||||
|
||||
swiftLauncher.add(name: "IntArray.copy", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).copy() }))
|
||||
swiftLauncher.add(name: "IntArray.copyManual", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).copyManual() }))
|
||||
swiftLauncher.add(name: "IntArray.filterAndCount", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).filterAndCount() }))
|
||||
swiftLauncher.add(name: "IntArray.filterSomeAndCount", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).filterSomeAndCount() }))
|
||||
swiftLauncher.add(name: "IntArray.filterAndMap", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).filterAndMap() }))
|
||||
swiftLauncher.add(name: "IntArray.filterAndMapManual", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).filterAndMapManual() }))
|
||||
swiftLauncher.add(name: "IntArray.filter", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).filter() }))
|
||||
swiftLauncher.add(name: "IntArray.filterSome", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).filterSome() }))
|
||||
swiftLauncher.add(name: "IntArray.filterPrime", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).filterPrime() }))
|
||||
swiftLauncher.add(name: "IntArray.filterManual", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).filterManual() }))
|
||||
swiftLauncher.add(name: "IntArray.filterSomeManual", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).filterSomeManual() }))
|
||||
swiftLauncher.add(name: "IntArray.countFilteredManual", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).countFilteredManual() }))
|
||||
swiftLauncher.add(name: "IntArray.countFilteredSomeManual", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).countFilteredSomeManual() }))
|
||||
swiftLauncher.add(name: "IntArray.countFilteredPrimeManual", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).countFilteredPrimeManual() }))
|
||||
swiftLauncher.add(name: "IntArray.countFiltered", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).countFiltered() }))
|
||||
swiftLauncher.add(name: "IntArray.countFilteredSome", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).countFilteredSome() }))
|
||||
swiftLauncher.add(name: "IntArray.countFilteredPrime", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).countFilteredPrime() }))
|
||||
swiftLauncher.add(name: "IntArray.countFilteredLocal", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).countFilteredLocal() }))
|
||||
swiftLauncher.add(name: "IntArray.countFilteredSomeLocal", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).countFilteredSomeLocal() }))
|
||||
swiftLauncher.add(name: "IntArray.reduce", benchmark: companion.create(ctor: { return IntArrayBenchmark() },
|
||||
lambda: { SwiftLauncher.intArrayBenchmark($0).reduce() }))
|
||||
|
||||
swiftLauncher.add(name: "IntBaseline.consume", benchmark: companion.create(ctor: { return IntBaselineBenchmark() },
|
||||
lambda: { SwiftLauncher.intBaselineBenchmark($0).consume() }))
|
||||
swiftLauncher.add(name: "IntBaseline.allocateArray", benchmark: companion.create(ctor: { return IntBaselineBenchmark() },
|
||||
lambda: { SwiftLauncher.intBaselineBenchmark($0).allocateArray() }))
|
||||
swiftLauncher.add(name: "IntBaseline.allocateArrayAndFill", benchmark: companion.create(ctor: { return IntBaselineBenchmark() },
|
||||
lambda: { SwiftLauncher.intBaselineBenchmark($0).allocateArrayAndFill() }))
|
||||
|
||||
swiftLauncher.add(name: "IntStream.copy", benchmark: companion.create(ctor: { return IntStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.intStreamBenchmark($0).copy() }))
|
||||
swiftLauncher.add(name: "IntStream.copyManual", benchmark: companion.create(ctor: { return IntStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.intStreamBenchmark($0).copyManual() }))
|
||||
swiftLauncher.add(name: "IntStream.filterAndCount", benchmark: companion.create(ctor: { return IntStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.intStreamBenchmark($0).filterAndCount() }))
|
||||
swiftLauncher.add(name: "IntStream.filterAndMap", benchmark: companion.create(ctor: { return IntStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.intStreamBenchmark($0).filterAndMap() }))
|
||||
swiftLauncher.add(name: "IntStream.filterAndMapManual", benchmark: companion.create(ctor: { return IntStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.intStreamBenchmark($0).filterAndMapManual() }))
|
||||
swiftLauncher.add(name: "IntStream.filter", benchmark: companion.create(ctor: { return IntStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.intStreamBenchmark($0).filter() }))
|
||||
swiftLauncher.add(name: "IntStream.filterManual", benchmark: companion.create(ctor: { return IntStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.intStreamBenchmark($0).filterManual() }))
|
||||
swiftLauncher.add(name: "IntStream.countFilteredManual", benchmark: companion.create(ctor: { return IntStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.intStreamBenchmark($0).countFilteredManual() }))
|
||||
swiftLauncher.add(name: "IntStream.countFiltered", benchmark: companion.create(ctor: { return IntStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.intStreamBenchmark($0).countFiltered() }))
|
||||
swiftLauncher.add(name: "IntStream.countFilteredLocal", benchmark: companion.create(ctor: { return IntStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.intStreamBenchmark($0).countFilteredLocal() }))
|
||||
swiftLauncher.add(name: "IntStream.reduce", benchmark: companion.create(ctor: { return IntStreamBenchmark() },
|
||||
lambda: { SwiftLauncher.intStreamBenchmark($0).reduce() }))
|
||||
|
||||
swiftLauncher.add(name: "Lambda.noncapturingLambda", benchmark: companion.create(ctor: { return LambdaBenchmark() },
|
||||
lambda: { SwiftLauncher.lambdaBenchmark($0).noncapturingLambda() }))
|
||||
swiftLauncher.add(name: "Lambda.noncapturingLambdaNoInline", benchmark: companion.create(ctor: { return LambdaBenchmark() },
|
||||
lambda: { SwiftLauncher.lambdaBenchmark($0).noncapturingLambdaNoInline() }))
|
||||
swiftLauncher.add(name: "Lambda.capturingLambda", benchmark: companion.create(ctor: { return LambdaBenchmark() },
|
||||
lambda: { SwiftLauncher.lambdaBenchmark($0).capturingLambda() }))
|
||||
swiftLauncher.add(name: "Lambda.capturingLambdaNoInline", benchmark: companion.create(ctor: { return LambdaBenchmark() },
|
||||
lambda: { SwiftLauncher.lambdaBenchmark($0).capturingLambdaNoInline() }))
|
||||
swiftLauncher.add(name: "Lambda.mutatingLambda", benchmark: companion.create(ctor: { return LambdaBenchmark() },
|
||||
lambda: { SwiftLauncher.lambdaBenchmark($0).mutatingLambda() }))
|
||||
swiftLauncher.add(name: "Lambda.mutatingLambdaNoInline", benchmark: companion.create(ctor: { return LambdaBenchmark() },
|
||||
lambda: { SwiftLauncher.lambdaBenchmark($0).mutatingLambdaNoInline() }))
|
||||
swiftLauncher.add(name: "Lambda.methodReference", benchmark: companion.create(ctor: { return LambdaBenchmark() },
|
||||
lambda: { SwiftLauncher.lambdaBenchmark($0).methodReference() }))
|
||||
swiftLauncher.add(name: "Lambda.methodReferenceNoInline", benchmark: companion.create(ctor: { return LambdaBenchmark() },
|
||||
lambda: { SwiftLauncher.lambdaBenchmark($0).methodReferenceNoInline() }))
|
||||
|
||||
swiftLauncher.add(name: "Loop.arrayLoop", benchmark: companion.create(ctor: { return LoopBenchmark() },
|
||||
lambda: { SwiftLauncher.loopBenchmark($0).arrayLoop() }))
|
||||
swiftLauncher.add(name: "Loop.arrayIndexLoop", benchmark: companion.create(ctor: { return LoopBenchmark() },
|
||||
lambda: { SwiftLauncher.loopBenchmark($0).arrayIndexLoop() }))
|
||||
swiftLauncher.add(name: "Loop.rangeLoop", benchmark: companion.create(ctor: { return LoopBenchmark() },
|
||||
lambda: { SwiftLauncher.loopBenchmark($0).rangeLoop() }))
|
||||
swiftLauncher.add(name: "Loop.arrayWhileLoop", benchmark: companion.create(ctor: { return LoopBenchmark() },
|
||||
lambda: { SwiftLauncher.loopBenchmark($0).arrayWhileLoop() }))
|
||||
swiftLauncher.add(name: "Loop.arrayForeachLoop", benchmark: companion.create(ctor: { return LoopBenchmark() },
|
||||
lambda: { SwiftLauncher.loopBenchmark($0).arrayForeachLoop() }))
|
||||
|
||||
swiftLauncher.add(name: "MatrixMap.add", benchmark: companion.create(ctor: { return MatrixMapBenchmark() },
|
||||
lambda: { SwiftLauncher.matrixMapBenchmark($0).add() }))
|
||||
|
||||
swiftLauncher.add(name: "ParameterNotNull.invokeOneArgWithNullCheck", benchmark: companion.create(ctor: { return ParameterNotNullAssertionBenchmark() },
|
||||
lambda: { SwiftLauncher.parameterNotNullAssertionBenchmark($0).invokeOneArgWithNullCheck() }))
|
||||
swiftLauncher.add(name: "ParameterNotNull.invokeOneArgWithoutNullCheck", benchmark: companion.create(ctor: { return ParameterNotNullAssertionBenchmark() },
|
||||
lambda: { SwiftLauncher.parameterNotNullAssertionBenchmark($0).invokeOneArgWithoutNullCheck() }))
|
||||
swiftLauncher.add(name: "ParameterNotNull.invokeTwoArgsWithNullCheck", benchmark: companion.create(ctor: { return ParameterNotNullAssertionBenchmark() },
|
||||
lambda: { SwiftLauncher.parameterNotNullAssertionBenchmark($0).invokeTwoArgsWithNullCheck() }))
|
||||
swiftLauncher.add(name: "ParameterNotNull.invokeTwoArgsWithoutNullCheck", benchmark: companion.create(ctor: { return ParameterNotNullAssertionBenchmark() },
|
||||
lambda: { SwiftLauncher.parameterNotNullAssertionBenchmark($0).invokeTwoArgsWithoutNullCheck() }))
|
||||
swiftLauncher.add(name: "ParameterNotNull.invokeEightArgsWithNullCheck", benchmark: companion.create(ctor: { return ParameterNotNullAssertionBenchmark() },
|
||||
lambda: { SwiftLauncher.parameterNotNullAssertionBenchmark($0).invokeEightArgsWithNullCheck() }))
|
||||
swiftLauncher.add(name: "ParameterNotNull.invokeEightArgsWithoutNullCheck", benchmark: companion.create(ctor: { return ParameterNotNullAssertionBenchmark() },
|
||||
lambda: { SwiftLauncher.parameterNotNullAssertionBenchmark($0).invokeEightArgsWithoutNullCheck() }))
|
||||
|
||||
swiftLauncher.add(name: "PrimeList.calcDirect", benchmark: companion.create(ctor: { return PrimeListBenchmark() },
|
||||
lambda: { SwiftLauncher.primeListBenchmark($0).calcDirect() }))
|
||||
swiftLauncher.add(name: "PrimeList.calcEratosthenes", benchmark: companion.create(ctor: { return PrimeListBenchmark() },
|
||||
lambda: { SwiftLauncher.primeListBenchmark($0).calcEratosthenes() }))
|
||||
|
||||
swiftLauncher.add(name: "String.stringConcat", benchmark: companion.create(ctor: { return StringBenchmark() },
|
||||
lambda: { SwiftLauncher.stringBenchmark($0).stringConcat() }))
|
||||
swiftLauncher.add(name: "String.stringConcatNullable", benchmark: companion.create(ctor: { return StringBenchmark() },
|
||||
lambda: { SwiftLauncher.stringBenchmark($0).stringConcatNullable() }))
|
||||
swiftLauncher.add(name: "String.stringBuilderConcat", benchmark: companion.create(ctor: { return StringBenchmark() },
|
||||
lambda: { SwiftLauncher.stringBenchmark($0).stringBuilderConcat() }))
|
||||
swiftLauncher.add(name: "String.stringBuilderConcatNullable", benchmark: companion.create(ctor: { return StringBenchmark() },
|
||||
lambda: { SwiftLauncher.stringBenchmark($0).stringBuilderConcatNullable() }))
|
||||
swiftLauncher.add(name: "String.summarizeSplittedCsv", benchmark: companion.create(ctor: { return StringBenchmark() },
|
||||
lambda: { SwiftLauncher.stringBenchmark($0).summarizeSplittedCsv() }))
|
||||
|
||||
swiftLauncher.add(name: "Switch.testSparseIntSwitch", benchmark: companion.create(ctor: { return SwitchBenchmark() },
|
||||
lambda: { SwiftLauncher.switchBenchmark($0).testSparseIntSwitch() }))
|
||||
swiftLauncher.add(name: "Switch.testDenseIntSwitch", benchmark: companion.create(ctor: { return SwitchBenchmark() },
|
||||
lambda: { SwiftLauncher.switchBenchmark($0).testDenseIntSwitch() }))
|
||||
swiftLauncher.add(name: "Switch.testConstSwitch", benchmark: companion.create(ctor: { return SwitchBenchmark() },
|
||||
lambda: { SwiftLauncher.switchBenchmark($0).testConstSwitch() }))
|
||||
swiftLauncher.add(name: "Switch.testObjConstSwitch", benchmark: companion.create(ctor: { return SwitchBenchmark() },
|
||||
lambda: { SwiftLauncher.switchBenchmark($0).testObjConstSwitch() }))
|
||||
swiftLauncher.add(name: "Switch.testVarSwitch", benchmark: companion.create(ctor: { return SwitchBenchmark() },
|
||||
lambda: { SwiftLauncher.switchBenchmark($0).testVarSwitch() }))
|
||||
swiftLauncher.add(name: "Switch.testStringsSwitch", benchmark: companion.create(ctor: { return SwitchBenchmark() },
|
||||
lambda: { SwiftLauncher.switchBenchmark($0).testStringsSwitch() }))
|
||||
swiftLauncher.add(name: "Switch.testEnumsSwitch", benchmark: companion.create(ctor: { return SwitchBenchmark() },
|
||||
lambda: { SwiftLauncher.switchBenchmark($0).testEnumsSwitch() }))
|
||||
swiftLauncher.add(name: "Switch.testDenseEnumsSwitch", benchmark: companion.create(ctor: { return SwitchBenchmark() },
|
||||
lambda: { SwiftLauncher.switchBenchmark($0).testDenseEnumsSwitch() }))
|
||||
swiftLauncher.add(name: "Switch.testSealedWhenSwitch", benchmark: companion.create(ctor: { return SwitchBenchmark() },
|
||||
lambda: { SwiftLauncher.switchBenchmark($0).testSealedWhenSwitch() }))
|
||||
|
||||
swiftLauncher.add(name: "WithIndicies.withIndicies", benchmark: companion.create(ctor: { return WithIndiciesBenchmark() },
|
||||
lambda: { SwiftLauncher.withIndiciesBenchmark($0).withIndicies() }))
|
||||
swiftLauncher.add(name: "WithIndicies.withIndiciesManual", benchmark: companion.create(ctor: { return WithIndiciesBenchmark() },
|
||||
lambda: { SwiftLauncher.withIndiciesBenchmark($0).withIndiciesManual() }))
|
||||
|
||||
swiftLauncher.add(name: "OctoTest", benchmark: BenchmarkEntry(
|
||||
lambda: { octoTest() }))
|
||||
|
||||
swiftLauncher.add(name: "Calls.finalMethod", benchmark: companion.create(ctor: { return CallsBenchmarks() },
|
||||
lambda: { SwiftLauncher.callsBenchmarks($0).finalMethodCall() }))
|
||||
swiftLauncher.add(name: "Calls.openMethodMonomorphic", benchmark: companion.create(ctor: { return CallsBenchmarks() },
|
||||
lambda: { SwiftLauncher.callsBenchmarks($0).classOpenMethodCall_MonomorphicCallsite() }))
|
||||
swiftLauncher.add(name: "Calls.openMethodBimorphic", benchmark: companion.create(ctor: { return CallsBenchmarks() },
|
||||
lambda: { SwiftLauncher.callsBenchmarks($0).classOpenMethodCall_BimorphicCallsite() }))
|
||||
swiftLauncher.add(name: "Calls.openMethodTrimorphic", benchmark: companion.create(ctor: { return CallsBenchmarks() },
|
||||
lambda: { SwiftLauncher.callsBenchmarks($0).classOpenMethodCall_TrimorphicCallsite() }))
|
||||
swiftLauncher.add(name: "Calls.interfaceMethodMonomorphic", benchmark: companion.create(ctor: { return CallsBenchmarks() },
|
||||
lambda: { SwiftLauncher.callsBenchmarks($0).interfaceMethodCall_MonomorphicCallsite() }))
|
||||
swiftLauncher.add(name: "Calls.interfaceMethodBimorphic", benchmark: companion.create(ctor: { return CallsBenchmarks() },
|
||||
lambda: { SwiftLauncher.callsBenchmarks($0).interfaceMethodCall_BimorphicCallsite() }))
|
||||
swiftLauncher.add(name: "Calls.interfaceMethodTrimorphic", benchmark: companion.create(ctor: { return CallsBenchmarks() },
|
||||
lambda: { SwiftLauncher.callsBenchmarks($0).interfaceMethodCall_TrimorphicCallsite() }))
|
||||
swiftLauncher.add(name: "Calls.interfaceMethodHexamorphic", benchmark: companion.create(ctor: { return CallsBenchmarks() },
|
||||
lambda: { SwiftLauncher.callsBenchmarks($0).interfaceMethodCall_HexamorphicCallsite() }))
|
||||
swiftLauncher.add(name: "Calls.returnBoxUnboxFolding", benchmark: companion.create(ctor: { return CallsBenchmarks() },
|
||||
lambda: { SwiftLauncher.callsBenchmarks($0).returnBoxUnboxFolding() }))
|
||||
|
||||
swiftLauncher.add(name: "CoordinatesSolver.solve", benchmark: companion.create(ctor: { return CoordinatesSolverBenchmark() },
|
||||
lambda: { SwiftLauncher.coordinatesSolverBenchmark($0).solve() }))
|
||||
|
||||
swiftLauncher.add(name: "GraphSolver.solve", benchmark: companion.create(ctor: { return GraphSolverBenchmark() },
|
||||
lambda: { SwiftLauncher.graphSolverBenchmark($0).solve() }))
|
||||
|
||||
swiftLauncher.add(name: "Casts.classCast", benchmark: companion.create(ctor: { return CastsBenchmark() },
|
||||
lambda: { SwiftLauncher.castsBenchmark($0).classCast() }))
|
||||
swiftLauncher.add(name: "Casts.interfaceCast", benchmark: companion.create(ctor: { return CastsBenchmark() },
|
||||
lambda: { SwiftLauncher.castsBenchmark($0).interfaceCast() }))
|
||||
|
||||
runner.runBenchmarks(args: args, run: { (arguments: BenchmarkArguments) -> [BenchmarkResult] in
|
||||
|
||||
if arguments is BaseBenchmarkArguments {
|
||||
let argumentsList: BaseBenchmarkArguments = arguments as! BaseBenchmarkArguments
|
||||
return swiftLauncher.launch(numWarmIterations: argumentsList.warmup,
|
||||
numberOfAttempts: argumentsList.repeat,
|
||||
prefix: argumentsList.prefix, filters: argumentsList.filter,
|
||||
filterRegexes: argumentsList.filterRegex,
|
||||
verbose: argumentsList.verbose)
|
||||
}
|
||||
return [BenchmarkResult]()
|
||||
}, parseArgs: { (args: KotlinArray, benchmarksListAction: (() -> KotlinUnit)) -> BenchmarkArguments? in
|
||||
return runner.parse(args: args, benchmarksListAction: swiftLauncher.benchmarksListAction) },
|
||||
collect: { (benchmarks: [BenchmarkResult], arguments: BenchmarkArguments) -> Void in
|
||||
runner.collect(results: benchmarks, arguments: arguments)
|
||||
}, benchmarksListAction: swiftLauncher.benchmarksListAction)
|
||||
@@ -0,0 +1,507 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
let zdf_win: [String] = ["-де",
|
||||
"-ка",
|
||||
"-либо",
|
||||
"-нибудь",
|
||||
"-с",
|
||||
"-таки",
|
||||
"-то",
|
||||
"а",
|
||||
"а-конто",
|
||||
"а-ля",
|
||||
"аба",
|
||||
"абажур",
|
||||
"абажурный",
|
||||
"абаз",
|
||||
"абазин",
|
||||
"абазинец",
|
||||
"абазинка",
|
||||
"абазинский",
|
||||
"абак",
|
||||
"абака",
|
||||
"аббат",
|
||||
"аббатиса",
|
||||
"аббатский",
|
||||
"аббатство",
|
||||
"аббревиатура",
|
||||
"аббревиатурный",
|
||||
"аббревиация",
|
||||
"абдикация",
|
||||
"абдомен",
|
||||
"абдоминальный",
|
||||
"абдуктор",
|
||||
"абдукторный",
|
||||
"абдукция",
|
||||
"абелит",
|
||||
"аберрационный",
|
||||
"аберрация",
|
||||
"абзац",
|
||||
"абзацный",
|
||||
"абиетин",
|
||||
"абиетиновый",
|
||||
"абиссальный",
|
||||
"абиссинец",
|
||||
"абиссинский",
|
||||
"абитуриент",
|
||||
"абитуриентка",
|
||||
"абитуриентский",
|
||||
"аблактировать",
|
||||
"аблактировка",
|
||||
"аблятив",
|
||||
"абляут",
|
||||
"абляция",
|
||||
"аболиционизм",
|
||||
"аболиционист",
|
||||
"аболиционистский",
|
||||
"аболиция",
|
||||
"абонемент",
|
||||
"абонементный",
|
||||
"абонент",
|
||||
"абонентка",
|
||||
"абонентный",
|
||||
"абонентский",
|
||||
"абонирование",
|
||||
"абонировать",
|
||||
"абонироваться",
|
||||
"абордаж",
|
||||
"абордажный",
|
||||
"абордировать",
|
||||
"абориген",
|
||||
"аборигенный",
|
||||
"аборт",
|
||||
"абортарий",
|
||||
"абортивный",
|
||||
"абортировать",
|
||||
"абразив",
|
||||
"абразивный",
|
||||
"абразионный",
|
||||
"абразия",
|
||||
"абракадабра",
|
||||
"абреже",
|
||||
"абрек",
|
||||
"абрикос",
|
||||
"абрикосный",
|
||||
"абрикосовка",
|
||||
"абрикосовый",
|
||||
"абрикотин",
|
||||
"абрис",
|
||||
"абрисный",
|
||||
"абсент",
|
||||
"абсентеизм",
|
||||
"абсентеист",
|
||||
"абсолют",
|
||||
"абсолютивный",
|
||||
"абсолютизирование",
|
||||
"абсолютизировать",
|
||||
"абсолютизм",
|
||||
"абсолютист",
|
||||
"абсолютистский",
|
||||
"абсолютность",
|
||||
"абсолютный",
|
||||
"абсолюция",
|
||||
"абсорбент",
|
||||
"абсорбер",
|
||||
"абсорбировать",
|
||||
"абсорбционный",
|
||||
"абсорбция",
|
||||
"абстинент",
|
||||
"абстрагирование",
|
||||
"абстрагировать",
|
||||
"абстрагироваться",
|
||||
"абстракт",
|
||||
"абстрактность",
|
||||
"абстрактный",
|
||||
"абстракционизм",
|
||||
"абстракционист",
|
||||
"абстракционистский",
|
||||
"абстракция",
|
||||
"абсурд",
|
||||
"абсурдность",
|
||||
"абсурдный",
|
||||
"абсцесс",
|
||||
"абсцисса",
|
||||
"абулия",
|
||||
"абхаз",
|
||||
"абхазец",
|
||||
"абхазка",
|
||||
"абхазский",
|
||||
"абцуг",
|
||||
"абштрих",
|
||||
"абъюрация",
|
||||
"абы",
|
||||
"авалист",
|
||||
"аваль",
|
||||
"авангард",
|
||||
"авангардизм",
|
||||
"авангардист",
|
||||
"авангардистский",
|
||||
"авангардный",
|
||||
"аванзал",
|
||||
"аванзальный",
|
||||
"аванкамера",
|
||||
"аванложа",
|
||||
"аванпорт",
|
||||
"аванпост",
|
||||
"аванпостный",
|
||||
"аванс",
|
||||
"авансирование",
|
||||
"авансировать",
|
||||
"авансовый",
|
||||
"авансом",
|
||||
"авансцена",
|
||||
"авантаж",
|
||||
"авантажный",
|
||||
"авантюра",
|
||||
"авантюризм",
|
||||
"авантюрин",
|
||||
"авантюриновый",
|
||||
"авантюрист",
|
||||
"авантюристический",
|
||||
"авантюристичный",
|
||||
"авантюристка",
|
||||
"авантюристский",
|
||||
"авантюрность",
|
||||
"авантюрный",
|
||||
"авар",
|
||||
"аварец",
|
||||
"аварийность",
|
||||
"аварийный",
|
||||
"аварийщик",
|
||||
"авария",
|
||||
"аварка",
|
||||
"аварский",
|
||||
"авгиев",
|
||||
"авгит",
|
||||
"авгур",
|
||||
"август",
|
||||
"августейший",
|
||||
"августинец",
|
||||
"августовский",
|
||||
"авдотка",
|
||||
"авеню",
|
||||
"аверс",
|
||||
"авестийский",
|
||||
"авиабаза",
|
||||
"авиабензин",
|
||||
"авиагоризонт",
|
||||
"авиадвигатель",
|
||||
"авиадесант",
|
||||
"авиадесантный",
|
||||
"авиазавод",
|
||||
"авиаконструктор",
|
||||
"авиалиния",
|
||||
"авиаматка",
|
||||
"авиамоделизм",
|
||||
"авиамоделист",
|
||||
"авиамодель",
|
||||
"авиамодельный",
|
||||
"авиамотор",
|
||||
"авиамоторный",
|
||||
"авианосец",
|
||||
"авиапочта",
|
||||
"авиаприбор",
|
||||
"авиапромышленность",
|
||||
"авиапромышленный",
|
||||
"авиаразведка",
|
||||
"авиастроение",
|
||||
"авиастроитель",
|
||||
"авиастроительный",
|
||||
"авиастроительство",
|
||||
"авиасъёмка",
|
||||
"авиатехник",
|
||||
"авиатор",
|
||||
"авиаторский",
|
||||
"авиатранспорт",
|
||||
"авиатранспортный",
|
||||
"авиатрасса",
|
||||
"авиационный",
|
||||
"авиация",
|
||||
"авиачасть",
|
||||
"авиашкола",
|
||||
"авиетка",
|
||||
"авизировать",
|
||||
"авизный",
|
||||
"авизо",
|
||||
"авитаминоз",
|
||||
"авитаминозный",
|
||||
"авифауна",
|
||||
"авокадо",
|
||||
"авось",
|
||||
"авоська",
|
||||
"аврал",
|
||||
"авралить",
|
||||
"авральный",
|
||||
"авран",
|
||||
"аврора",
|
||||
"австралиец",
|
||||
"австралийка",
|
||||
"австралийский",
|
||||
"австралопитек",
|
||||
"австриец",
|
||||
"австрийка",
|
||||
"австрийский",
|
||||
"австрияк",
|
||||
"австриячка",
|
||||
"австро-венгерский",
|
||||
"автаркический",
|
||||
"автаркия",
|
||||
"авто",
|
||||
"автобаза",
|
||||
"автобиографический",
|
||||
"автобиографичность",
|
||||
"автобиографичный",
|
||||
"автобиография",
|
||||
"автоблокировка",
|
||||
"автоблокировочный",
|
||||
"автобус",
|
||||
"автобусник",
|
||||
"автобусный",
|
||||
"автовакцина",
|
||||
"автовесы",
|
||||
"автовокзал",
|
||||
"автогамия",
|
||||
"автоген",
|
||||
"автогенез",
|
||||
"автогенератор",
|
||||
"автогенный",
|
||||
"автогенщик",
|
||||
"автогипноз",
|
||||
"автогонки",
|
||||
"автогравюра",
|
||||
"автограф",
|
||||
"автографический",
|
||||
"автография",
|
||||
"автогужевой",
|
||||
"автодидакт",
|
||||
"автодоение",
|
||||
"автодорожник",
|
||||
"автодорожный",
|
||||
"автодрезина",
|
||||
"автодром",
|
||||
"автожир",
|
||||
"автозавод",
|
||||
"автозаводец",
|
||||
"автозаводский",
|
||||
"автозаводской",
|
||||
"автозаправочный",
|
||||
"автозаправщик",
|
||||
"автоинспектор",
|
||||
"автоинспекция",
|
||||
"автокар",
|
||||
"автокара",
|
||||
"автокатализ",
|
||||
"автокефалия",
|
||||
"автокефальный",
|
||||
"автоклав",
|
||||
"автоклуб",
|
||||
"автоколонна",
|
||||
"автокомбинат",
|
||||
"автокран",
|
||||
"автократ",
|
||||
"автократический",
|
||||
"автократия",
|
||||
"автокружок",
|
||||
"автол",
|
||||
"автолавка",
|
||||
"автолиз",
|
||||
"автолитография",
|
||||
"автолюбитель",
|
||||
"автолюбительство",
|
||||
"автомагистраль",
|
||||
"автомат",
|
||||
"автоматизация",
|
||||
"автоматизирование",
|
||||
"автоматизировать",
|
||||
"автоматизироваться",
|
||||
"автоматизм",
|
||||
"автоматика",
|
||||
"автоматический",
|
||||
"автоматичность",
|
||||
"автоматичный",
|
||||
"автоматный",
|
||||
"автоматчик",
|
||||
"автоматчица",
|
||||
"автомашина",
|
||||
"автомашинист",
|
||||
"автомеханик",
|
||||
"автомобилестроение",
|
||||
"автомобилестроитель",
|
||||
"автомобилестроительный",
|
||||
"автомобилизация",
|
||||
"автомобилизм",
|
||||
"автомобилист",
|
||||
"автомобилистка",
|
||||
"автомобиль",
|
||||
"автомобильный",
|
||||
"автомобильчик",
|
||||
"автоморфизм",
|
||||
"автомотоклуб",
|
||||
"автомоторный",
|
||||
"автомотошкола",
|
||||
"автомотриса",
|
||||
"автономист",
|
||||
"автономистский",
|
||||
"автономический",
|
||||
"автономия",
|
||||
"автономность",
|
||||
"автономный",
|
||||
"автопарк",
|
||||
"автоперевозка",
|
||||
"автопилот",
|
||||
"автопластика",
|
||||
"автоплуг",
|
||||
"автопогрузчик",
|
||||
"автоподъёмник",
|
||||
"автопоезд",
|
||||
"автопоилка",
|
||||
"автопокрышка",
|
||||
"автопортрет",
|
||||
"автопробег",
|
||||
"автопромышленность",
|
||||
"автор",
|
||||
"авторалли",
|
||||
"авторегулятор",
|
||||
"авторемонтник",
|
||||
"авторемонтный",
|
||||
"автореферат",
|
||||
"авторефрижератор",
|
||||
"авторизация",
|
||||
"авторизованный",
|
||||
"авторизовать",
|
||||
"авторитарность",
|
||||
"авторитарный",
|
||||
"авторитет",
|
||||
"авторитетность",
|
||||
"авторитетный",
|
||||
"авторота",
|
||||
"авторские",
|
||||
"авторский",
|
||||
"авторство",
|
||||
"авторулевой",
|
||||
"авторучка",
|
||||
"автосани",
|
||||
"автосборка",
|
||||
"автосварщик",
|
||||
"автоспорт",
|
||||
"автостанция",
|
||||
"автостоп",
|
||||
"автострада",
|
||||
"автостроение",
|
||||
"автостроитель",
|
||||
"автосцепка",
|
||||
"автотележка",
|
||||
"автотип",
|
||||
"автотипический",
|
||||
"автотипия",
|
||||
"автотипный",
|
||||
"автотомия",
|
||||
"автотормоз",
|
||||
"автотормозной",
|
||||
"автотракторный",
|
||||
"автотранспорт",
|
||||
"автотранспортный",
|
||||
"автотрансформатор",
|
||||
"автотрасса",
|
||||
"автотуризм",
|
||||
"автотурист",
|
||||
"автоукладчик",
|
||||
"автофургон",
|
||||
"автохозяйство",
|
||||
"автохром",
|
||||
"автохромный",
|
||||
"автохтон",
|
||||
"автохтонный",
|
||||
"автоцистерна",
|
||||
"авточасть",
|
||||
"автошкола",
|
||||
"автоштурман",
|
||||
"авуары",
|
||||
"ага",
|
||||
"ага-хан",
|
||||
"агава",
|
||||
"агалит",
|
||||
"агальматолит",
|
||||
"агама",
|
||||
"агами",
|
||||
"агамия",
|
||||
"агамогония",
|
||||
"агар-агар",
|
||||
"агарный",
|
||||
"агаровый",
|
||||
"агарянин",
|
||||
"агат",
|
||||
"агатный",
|
||||
"агатовый",
|
||||
"агглютинативность",
|
||||
"агглютинативный",
|
||||
"агглютинация",
|
||||
"агглютинин",
|
||||
"агглютинирующий",
|
||||
"аггравация",
|
||||
"агент",
|
||||
"агентский",
|
||||
"агентство",
|
||||
"агентура",
|
||||
"агентурный",
|
||||
"агиографический",
|
||||
"агиография",
|
||||
"агиология",
|
||||
"агитатор",
|
||||
"агитаторский",
|
||||
"агитаторша",
|
||||
"агитационный",
|
||||
"агитация",
|
||||
"агитбригада",
|
||||
"агитировать",
|
||||
"агитка",
|
||||
"агиткампания",
|
||||
"агитмассовый",
|
||||
"агитпоезд",
|
||||
"агитпроп",
|
||||
"агитпункт",
|
||||
"аглицкий",
|
||||
"агломерат",
|
||||
"агломератчик",
|
||||
"агломерационный",
|
||||
"агломерация",
|
||||
"агломерировать",
|
||||
"агломерироваться",
|
||||
"агнат",
|
||||
"агнец",
|
||||
"агнозия",
|
||||
"агностик",
|
||||
"агностицизм",
|
||||
"агностический",
|
||||
"агонизировать",
|
||||
"агонический",
|
||||
"агония",
|
||||
"агорафобия",
|
||||
"аграмант",
|
||||
"аграмантовый",
|
||||
"аграрий",
|
||||
"аграрник",
|
||||
"аграрный",
|
||||
"аграф",
|
||||
"аграфия",
|
||||
"агрегат",
|
||||
"агрегатный",
|
||||
"агреман",
|
||||
"агрессивность",
|
||||
"агрессивный",
|
||||
"агрессия",
|
||||
"агрессор",
|
||||
"агрикультура",
|
||||
"агрикультурный",
|
||||
"агробаза",
|
||||
"агробиолог",
|
||||
"агробиологический",
|
||||
"агробиология",
|
||||
"агроботаника",
|
||||
"агрозоотехника",
|
||||
"агромелиорация"
|
||||
]
|
||||
@@ -0,0 +1,295 @@
|
||||
import org.jetbrains.kotlin.RegressionsReporter
|
||||
import org.jetbrains.kotlin.RegressionsSummaryReporter
|
||||
import org.jetbrains.kotlin.BuildRegister
|
||||
import org.jetbrains.kotlin.MPPTools
|
||||
|
||||
buildscript {
|
||||
apply from: "$rootProject.projectDir/gradle/kotlinGradlePlugin.gradle"
|
||||
repositories {
|
||||
maven {
|
||||
url 'https://cache-redirector.jetbrains.com/jcenter'
|
||||
}
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
def rootBuildDirectory = rootProject.projectDir
|
||||
|
||||
task konanRun {
|
||||
subprojects.each {
|
||||
dependsOn "${it.path}:konanRun"
|
||||
}
|
||||
}
|
||||
|
||||
task jvmRun {
|
||||
subprojects.each {
|
||||
dependsOn "${it.path}:jvmRun"
|
||||
}
|
||||
}
|
||||
|
||||
task clean {
|
||||
subprojects.each {
|
||||
dependsOn "${it.path}:clean"
|
||||
}
|
||||
doLast {
|
||||
delete "${buildDir.absolutePath}"
|
||||
}
|
||||
}
|
||||
|
||||
defaultTasks 'konanRun'
|
||||
|
||||
private static String getAnalyzerTargetName() {
|
||||
// Copy-pasted from tools/benchmarksAnalyzer/build.gradle.
|
||||
String target = System.getProperty("os.name")
|
||||
if (target == 'Linux') return 'linux'
|
||||
if (target.startsWith('Windows')) return 'windows'
|
||||
if (target.startsWith('Mac')) return 'macos'
|
||||
return 'unknown'
|
||||
}
|
||||
|
||||
private String findAnalyzerBinary() {
|
||||
String result = "${rootProject.projectDir}/${analyzerToolDirectory}/${getAnalyzerTargetName()}/" +
|
||||
"${analyzerTool}ReleaseExecutable/${analyzerTool}${MPPTools.getNativeProgramExtension()}"
|
||||
|
||||
if (file(result).exists()) return result
|
||||
else return null
|
||||
}
|
||||
|
||||
// Produce and send slack report.
|
||||
task slackReport(type: RegressionsReporter) {
|
||||
def analyzerBinary = MPPTools.findFile("${analyzerTool}${MPPTools.getNativeProgramExtension()}",
|
||||
"${rootBuildDirectory}/${analyzerToolDirectory}")
|
||||
def teamcityConfig = System.getenv("TEAMCITY_BUILD_PROPERTIES_FILE")
|
||||
if (teamcityConfig && analyzerBinary != null) {
|
||||
// Create folder for report (root Kotlin project settings make create report in separate folder).
|
||||
def reportDirectory = new File(outputReport).parentFile
|
||||
mkdir reportDirectory
|
||||
def targetsResults = new File(new File("${rootBuildDirectory}"), "targetsResults").toString()
|
||||
mkdir targetsResults
|
||||
currentBenchmarksReportFile = "${buildDir.absolutePath}/${nativeJson}"
|
||||
analyzer = analyzerBinary
|
||||
htmlReport = outputReport
|
||||
defaultBranch = project.findProperty('kotlin.native.default.branch') ?: "master"
|
||||
def target = System.getProperty("os.name")
|
||||
summaryFile = "${targetsResults}/${target}.txt"
|
||||
bundleBuild = project.findProperty('kotlin.bundleBuild') == null ? false : true
|
||||
}
|
||||
}
|
||||
|
||||
task slackSummary(type: RegressionsSummaryReporter) {
|
||||
targetsResultFiles = ['Linux': "${rootBuildDirectory}/targetsResults/Linux.txt".toString(),
|
||||
'MacOSX': "${rootBuildDirectory}/targetsResults/Mac OS X.txt".toString(),
|
||||
'Windows': "${rootBuildDirectory}/targetsResults/Windows 10.txt".toString()]
|
||||
}
|
||||
|
||||
private String getUploadedFile(String fileName) {
|
||||
def teamcityConfig = System.getenv("TEAMCITY_BUILD_PROPERTIES_FILE")
|
||||
if (teamcityConfig) {
|
||||
def buildProperties = new Properties()
|
||||
buildProperties.load(new FileInputStream(teamcityConfig))
|
||||
def buildNumber = buildProperties.getProperty("build.number")
|
||||
def target = System.getProperty("os.name").replaceAll("\\s", "")
|
||||
return "${target}/${buildNumber}/${fileName}"
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private def uploadBenchmarkResultToArtifactory(String fileName) {
|
||||
def teamcityConfig = System.getenv("TEAMCITY_BUILD_PROPERTIES_FILE")
|
||||
if (teamcityConfig) {
|
||||
def uploadedFile = getUploadedFile(fileName)
|
||||
def buildProperties = new Properties()
|
||||
buildProperties.load(new FileInputStream(teamcityConfig))
|
||||
def password = buildProperties.getProperty("artifactory.apikey")
|
||||
MPPTools.uploadFileToArtifactory("${artifactoryUrl}", "${artifactoryRepo}",
|
||||
uploadedFile, "${buildDir.absolutePath}/${fileName}", password)
|
||||
}
|
||||
}
|
||||
|
||||
// Register external benchmarks reports (e.g. results of libraries benchmarks)
|
||||
task registerExternalBenchmarks {
|
||||
doLast {
|
||||
def reports = externalReports.split(';')
|
||||
def jsonReports = []
|
||||
reports.each {
|
||||
def reportFile = new File(buildDir, it)
|
||||
if (!reportFile.exists())
|
||||
return
|
||||
|
||||
def lines = reportFile.readLines()
|
||||
if (lines.size < 4) {
|
||||
project.logger.warn("Couldn't use report to register benchmarks. Wrong format.")
|
||||
return
|
||||
}
|
||||
def name = lines[0]
|
||||
def options = lines[1]
|
||||
if (!options.startsWith("OPTIONS")) {
|
||||
project.logger.warn("Couldn't use report to register benchmarks. Wrong format in options description.")
|
||||
return
|
||||
}
|
||||
def optionsList = options.replace("OPTIONS ", "").replaceAll("\\[|\\]", "").split(",\\s*").toList()
|
||||
def status = lines[2]
|
||||
def compileTime = null
|
||||
def codeSize = null
|
||||
lines.drop(3).each {
|
||||
if (it.startsWith("COMPILE_TIME")) {
|
||||
compileTime = it
|
||||
}
|
||||
if (it.startsWith("CODE_SIZE")) {
|
||||
codeSize = it
|
||||
}
|
||||
}
|
||||
// Create benchmarks report.
|
||||
def properties = [
|
||||
"cpu": System.getProperty("os.arch"),
|
||||
"os": System.getProperty("os.name"),
|
||||
"jdkVersion": System.getProperty("java.version"),
|
||||
"jdkVendor": System.getProperty("java.vendor"),
|
||||
"kotlinVersion": kotlinVersion,
|
||||
"type": "native",
|
||||
"compilerVersion": konanVersion,
|
||||
"flags": optionsList,
|
||||
"benchmarks": "[]"]
|
||||
if (compileTime != null) {
|
||||
def compileBenchmark = MPPTools.toCompileBenchmark(compileTime, status, name)
|
||||
properties += ["compileTime": [compileBenchmark]]
|
||||
}
|
||||
if (codeSize != null) {
|
||||
properties += ["codeSize": MPPTools.toCodeSizeBenchmark(codeSize, status, name)]
|
||||
}
|
||||
def output = MPPTools.createJsonReport(properties)
|
||||
def jsonFile = new File(buildDir, it.replace(".txt", ".json"))
|
||||
jsonFile.write(output)
|
||||
jsonReports.add(jsonFile)
|
||||
}
|
||||
def merged = MPPTools.mergeReports(jsonReports)
|
||||
if (!merged.isEmpty()) {
|
||||
mkdir buildDir.absolutePath
|
||||
new File(buildDir, externalBenchmarksReport).write(merged)
|
||||
uploadBenchmarkResultToArtifactory(externalBenchmarksReport)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task registerBuild(type: BuildRegister) {
|
||||
onlyBranch = project.findProperty('kotlin.register.branch')
|
||||
def uploadedFile = getUploadedFile(nativeJson)
|
||||
if (uploadedFile != null) {
|
||||
println("Use file from Artifacrory $uploadedFile")
|
||||
fileWithResult = uploadedFile
|
||||
}
|
||||
// Get bundle size.
|
||||
bundleSize = null
|
||||
if (project.findProperty('kotlin.bundleBuild') != null) {
|
||||
def dist = findProperty('kotlin.native.home') ?: 'dist'
|
||||
dist = (new File(dist)).isAbsolute() ? dist : "${project.getProjectDir()}/$dist"
|
||||
bundleSize = (new File(dist)).directorySize()
|
||||
}
|
||||
}
|
||||
|
||||
task registerExternalBuild(type: BuildRegister) {
|
||||
onlyBranch = project.findProperty('kotlin.register.branch')
|
||||
def uploadedFile = getUploadedFile(externalBenchmarksReport)
|
||||
if (uploadedFile != null) {
|
||||
println("Use file from Artifacrory $uploadedFile")
|
||||
fileWithResult = uploadedFile
|
||||
} else {
|
||||
fileWithResult = externalBenchmarksReport
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerExternalBenchmarks.finalizedBy registerExternalBuild
|
||||
|
||||
def mergeReports(String fileName) {
|
||||
def reports = []
|
||||
subprojects.each {
|
||||
def reportFile = new File("${it.buildDir.absolutePath}/${fileName}")
|
||||
if (reportFile.exists()) {
|
||||
reports.add(reportFile)
|
||||
}
|
||||
}
|
||||
def output = MPPTools.mergeReports(reports)
|
||||
mkdir buildDir.absolutePath
|
||||
new File("${buildDir.absolutePath}/${fileName}").write(output)
|
||||
}
|
||||
|
||||
task mergeNativeReports {
|
||||
doLast {
|
||||
mergeReports(nativeJson)
|
||||
uploadBenchmarkResultToArtifactory(nativeJson)
|
||||
}
|
||||
}
|
||||
|
||||
task mergeJvmReports {
|
||||
doLast {
|
||||
mergeReports(jvmJson)
|
||||
uploadBenchmarkResultToArtifactory(jvmJson)
|
||||
}
|
||||
}
|
||||
|
||||
subprojects.each {
|
||||
it.afterEvaluate {
|
||||
it.jvmJsonReport.finalizedBy mergeJvmReports
|
||||
it.konanJsonReport.finalizedBy mergeNativeReports
|
||||
}
|
||||
}
|
||||
|
||||
task teamCityStat(type:Exec) {
|
||||
def analyzer = findAnalyzerBinary()
|
||||
if (analyzer != null) {
|
||||
commandLine "${analyzer}", "-r", "teamcity", "${buildDir.absolutePath}/${nativeJson}"
|
||||
} else {
|
||||
println("No analyzer $analyzerTool found in subdirectories of ${rootBuildDirectory}/${analyzerToolDirectory}")
|
||||
}
|
||||
}
|
||||
|
||||
task cinterop {
|
||||
dependsOn 'clean'
|
||||
dependsOn 'cinterop:konanRun'
|
||||
}
|
||||
|
||||
task framework {
|
||||
dependsOn 'clean'
|
||||
dependsOn 'framework:konanRun'
|
||||
}
|
||||
|
||||
task helloworld {
|
||||
dependsOn 'clean'
|
||||
dependsOn 'helloworld:konanRun'
|
||||
}
|
||||
|
||||
task objcinterop {
|
||||
dependsOn 'clean'
|
||||
dependsOn 'objcinterop:konanRun'
|
||||
}
|
||||
|
||||
task ring {
|
||||
dependsOn 'clean'
|
||||
dependsOn 'ring:konanRun'
|
||||
}
|
||||
|
||||
task numerical {
|
||||
dependsOn 'clean'
|
||||
dependsOn 'numerical:konanRun'
|
||||
}
|
||||
|
||||
task startup {
|
||||
dependsOn 'clean'
|
||||
dependsOn 'startup:konanRun'
|
||||
}
|
||||
|
||||
task swiftinterop {
|
||||
dependsOn 'clean'
|
||||
dependsOn 'swiftinterop:konanRun'
|
||||
}
|
||||
|
||||
task videoplayer {
|
||||
dependsOn 'clean'
|
||||
dependsOn 'videoplayer:konanRun'
|
||||
}
|
||||
|
||||
task KotlinVsSwift {
|
||||
dependsOn 'clean'
|
||||
dependsOn 'KotlinVsSwift:konanRun'
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
|
||||
|
||||
plugins {
|
||||
id("benchmarking")
|
||||
}
|
||||
|
||||
val defaultBuildType = NativeBuildType.RELEASE
|
||||
|
||||
benchmark {
|
||||
applicationName = "Cinterop"
|
||||
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"))
|
||||
}
|
||||
|
||||
val native = kotlin.targets.getByName("native") as KotlinNativeTarget
|
||||
native.compilations["main"].cinterops {
|
||||
create("macros")
|
||||
create("struct")
|
||||
create("types")
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
kotlin.native.home=../../dist
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.structsBenchmarks
|
||||
|
||||
actual fun structBenchmark() {
|
||||
error("Benchmark structBenchmark is unsupported on JVM!")
|
||||
}
|
||||
actual fun unionBenchmark() {
|
||||
error("Benchmark unionBenchmark is unsupported on JVM!")
|
||||
}
|
||||
actual fun enumBenchmark() {
|
||||
error("Benchmark enumBenchmark is unsupported on JVM!")
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.structsProducedByMacrosBenchmarks
|
||||
|
||||
actual fun macrosBenchmark() {
|
||||
error("Benchmark macrosBenchmark is unsupported on JVM!")
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.typesBenchmarks
|
||||
|
||||
actual class StringBenchmark actual constructor() {
|
||||
actual fun stringToCBenchmark() {
|
||||
error("Benchmark stringToCBenchmark is unsupported on JVM!")
|
||||
}
|
||||
|
||||
actual fun stringToKotlinBenchmark() {
|
||||
error("Benchmark stringToKotlinBenchmark is unsupported on JVM!")
|
||||
}
|
||||
}
|
||||
|
||||
actual class IntBenchmark actual constructor() {
|
||||
actual fun intBenchmark() {
|
||||
error("Benchmark intBenchmark is unsupported on JVM!")
|
||||
}
|
||||
}
|
||||
|
||||
actual class BoxedIntBenchmark actual constructor() {
|
||||
actual fun boxedIntBenchmark() {
|
||||
error("Benchmark boxedIntBenchmark is unsupported on JVM!")
|
||||
}
|
||||
}
|
||||
|
||||
actual class IntMatrixBenchmark actual constructor() {
|
||||
actual fun intMatrixBenchmark() {
|
||||
error("Benchmark intMatrixBenchmark is unsupported on JVM!")
|
||||
}
|
||||
}
|
||||
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.structsBenchmarks
|
||||
import kotlinx.cinterop.*
|
||||
import platform.posix.*
|
||||
import kotlin.math.sqrt
|
||||
|
||||
const val benchmarkSize = 10000
|
||||
|
||||
actual fun structBenchmark() {
|
||||
memScoped {
|
||||
val containsFunction = staticCFunction<CPointer<ElementS>?, CPointer<ElementS>?, Int> { first, second ->
|
||||
if (first == null || second == null) {
|
||||
0
|
||||
} else if (first.pointed.string.toKString().contains(second.pointed.string.toKString())) {
|
||||
1
|
||||
}
|
||||
else {
|
||||
0
|
||||
}
|
||||
}
|
||||
val elementsList = mutableListOf<ElementS>()
|
||||
// Fill list.
|
||||
for (i in 1..benchmarkSize) {
|
||||
val element = alloc<ElementS>()
|
||||
element.floatValue = i + sqrt(i.toDouble()).toFloat()
|
||||
element.integer = i.toLong()
|
||||
sprintf(element.string, "%d", i)
|
||||
element.contains = containsFunction
|
||||
|
||||
elementsList.add(element)
|
||||
}
|
||||
val summary = elementsList.map { multiplyElementS(it.readValue(), (0..10).random()) }
|
||||
.reduce { acc, it -> sumElementSPtr(acc.ptr, it.ptr)!!.pointed.readValue() }
|
||||
val intValue = summary.useContents { integer }
|
||||
elementsList.last().contains!!(elementsList.last().ptr, elementsList.first().ptr)
|
||||
}
|
||||
}
|
||||
|
||||
actual fun unionBenchmark() {
|
||||
memScoped {
|
||||
val elementsList = mutableListOf<ElementU>()
|
||||
// Fill list.
|
||||
for (i in 1..benchmarkSize) {
|
||||
val element = alloc<ElementU>()
|
||||
element.integer = i.toLong()
|
||||
elementsList.add(element)
|
||||
}
|
||||
elementsList.forEach {
|
||||
it.floatValue = it.integer + sqrt(it.integer.toDouble()).toFloat()
|
||||
}
|
||||
val summary = elementsList.map { multiplyElementU(it.readValue(), (0..10).random()) }
|
||||
.reduce { acc, it -> sumElementUPtr(acc.ptr, it.ptr)!!.pointed.readValue() }
|
||||
summary.useContents { integer }
|
||||
}
|
||||
}
|
||||
|
||||
actual fun enumBenchmark() {
|
||||
val days = arrayOf("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
|
||||
val enumValues = mutableListOf<WeekDay>()
|
||||
for (i in 1..benchmarkSize) {
|
||||
enumValues.add(getWeekDay(days[(0..6).random()]))
|
||||
}
|
||||
enumValues.forEach {
|
||||
isWeekEnd(it)
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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.structsProducedByMacrosBenchmarks
|
||||
import kotlinx.cinterop.*
|
||||
import kotlin.math.abs
|
||||
|
||||
const val benachmarkSize = 1000
|
||||
|
||||
actual fun macrosBenchmark() {
|
||||
memScoped {
|
||||
val ints = new_list_int()
|
||||
for (i in 1..benachmarkSize) {
|
||||
list_push_front_int(ints, i)
|
||||
}
|
||||
val floats = new_list_float()
|
||||
// Copy integer list to float one.
|
||||
ints?.pointed?.apply {
|
||||
var current = _first
|
||||
while(current != null) {
|
||||
list_push_front_float(floats, current?.pointed?._data?.toFloat()
|
||||
?: error("Null elements in list are not expected!")
|
||||
)
|
||||
current = current?.pointed?._next
|
||||
}
|
||||
}
|
||||
// Reverse list.
|
||||
var previous: CPointer<list_elem_float>? = null
|
||||
var current = floats?.pointed?._first
|
||||
while (current != null) {
|
||||
val next = current?.pointed?._next
|
||||
current?.pointed?._next = previous
|
||||
previous = current
|
||||
current = next
|
||||
}
|
||||
floats?.pointed?._first = previous
|
||||
free_list_int(ints)
|
||||
try {
|
||||
if (abs(list_front_float(floats) - benachmarkSize.toFloat()) > 0.00001) {
|
||||
error("Wrong first element!")
|
||||
}
|
||||
} finally {
|
||||
free_list_float(floats)
|
||||
}
|
||||
}
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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.typesBenchmarks
|
||||
|
||||
import kotlin.random.Random
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
const val benchmarkSize = 1000
|
||||
|
||||
actual class StringBenchmark actual constructor() {
|
||||
val charPool: List<Char> = ('a'..'z') + ('A'..'Z') + ('0'..'9')
|
||||
val randomString = generateRandomString()
|
||||
val randomChar = charPool[Random.nextInt(0, charPool.size)]
|
||||
val strings = mutableListOf<String>()
|
||||
|
||||
init {
|
||||
// Generate random strings.
|
||||
for (i in 1..benchmarkSize) {
|
||||
strings.add(generateRandomString())
|
||||
}
|
||||
}
|
||||
|
||||
fun generateRandomString(): String {
|
||||
return (1..benchmarkSize)
|
||||
.map { i -> Random.nextInt(0, charPool.size) }
|
||||
.map(charPool::get)
|
||||
.joinToString("")
|
||||
}
|
||||
|
||||
actual fun stringToCBenchmark() {
|
||||
// Generate random strings.
|
||||
for (i in 1..benchmarkSize) {
|
||||
charFrequency(randomString, randomChar.toByte())
|
||||
}
|
||||
}
|
||||
|
||||
actual fun stringToKotlinBenchmark() {
|
||||
memScoped {
|
||||
val result = StringBuilder()
|
||||
for (i in 1..benchmarkSize) {
|
||||
val pointer = findSuitableString(strings.toCStringArray(this), benchmarkSize, "a")
|
||||
val str = pointer?.toKString()
|
||||
result.append(str)
|
||||
freeSuitableString(pointer)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
actual class IntMatrixBenchmark actual constructor(){
|
||||
val matrixSize = 1000
|
||||
val first = generateMatrix(matrixSize)
|
||||
val second = generateMatrix(matrixSize)
|
||||
|
||||
fun generateMatrix(size: Int): Array<IntArray> {
|
||||
val matrix = Array(size, { IntArray(size) })
|
||||
for (i in (0 until size)) {
|
||||
for (j in (0 until size)) {
|
||||
matrix[i][j] = (1..20).random()
|
||||
}
|
||||
}
|
||||
return matrix
|
||||
}
|
||||
|
||||
actual fun intMatrixBenchmark() {
|
||||
memScoped {
|
||||
val result = allocArray<CPointerVar<IntVar>>(matrixSize)
|
||||
for (i in (0 until matrixSize)) {
|
||||
result[i] = allocArray<IntVar>(matrixSize)
|
||||
}
|
||||
val resultMatrix = multiplyMatrix(matrixSize, matrixSize,
|
||||
first.map { it.toCValues().ptr }.toCValues().ptr,
|
||||
matrixSize, matrixSize,
|
||||
second.map { it.toCValues().ptr }.toCValues().ptr)
|
||||
val resultOutput = buildString {
|
||||
for (i in (0 until matrixSize)) {
|
||||
for (j in (0 until matrixSize)) {
|
||||
append(resultMatrix!![i]!![j])
|
||||
append(" ")
|
||||
}
|
||||
append("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
actual class IntBenchmark actual constructor() {
|
||||
val size = 20
|
||||
val array = Array<Int>(size, { (0 until size).random() })
|
||||
|
||||
actual fun intBenchmark() {
|
||||
for (i in 1..benchmarkSize) {
|
||||
average(array[0], array[1], array[2], array[3], array[4], array[5], array[6], array[7], array[8],
|
||||
array[9], array[10], array[11], array[12], array[13], array[14], array[15], array[16],
|
||||
array[17], array[18], array[19])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
actual class BoxedIntBenchmark actual constructor() {
|
||||
val size = 20
|
||||
val array = Array<Int?>(size, { null })
|
||||
|
||||
init {
|
||||
for (i in (0 until size)) {
|
||||
val element: Int? = (0 until size).random()
|
||||
array[i] = element
|
||||
}
|
||||
}
|
||||
|
||||
actual fun boxedIntBenchmark() {
|
||||
for (i in 1..benchmarkSize) {
|
||||
average(array[0]!!, array[1]!!, array[2]!!, array[3]!!, array[4]!!, array[5]!!, array[6]!!, array[7]!!, array[8]!!,
|
||||
array[9]!!, array[10]!!, array[11]!!, array[12]!!, array[13]!!, array[14]!!, array[15]!!, array[16]!!,
|
||||
array[17]!!, array[18]!!, array[19]!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.structsProducedByMacrosBenchmarks.*
|
||||
import org.jetbrains.benchmarksLauncher.*
|
||||
import org.jetbrains.structsBenchmarks.*
|
||||
import org.jetbrains.typesBenchmarks.*
|
||||
import kotlinx.cli.*
|
||||
|
||||
class CinteropLauncher : Launcher() {
|
||||
override val benchmarks = BenchmarksCollection(
|
||||
mutableMapOf(
|
||||
"macros" to BenchmarkEntry(::macrosBenchmark),
|
||||
"struct" to BenchmarkEntry(::structBenchmark),
|
||||
"union" to BenchmarkEntry(::unionBenchmark),
|
||||
"enum" to BenchmarkEntry(::enumBenchmark),
|
||||
"stringToC" to BenchmarkEntryWithInit.create(::StringBenchmark, { stringToCBenchmark() }),
|
||||
"stringToKotlin" to BenchmarkEntryWithInit.create(::StringBenchmark, { stringToKotlinBenchmark() }),
|
||||
"intMatrix" to BenchmarkEntryWithInit.create(::IntMatrixBenchmark, { intMatrixBenchmark() }),
|
||||
"int" to BenchmarkEntryWithInit.create(::IntBenchmark, { intBenchmark() }),
|
||||
"boxedInt" to BenchmarkEntryWithInit.create(::BoxedIntBenchmark, { boxedIntBenchmark() })
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val launcher = CinteropLauncher()
|
||||
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)
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.structsBenchmarks
|
||||
|
||||
expect fun structBenchmark()
|
||||
expect fun unionBenchmark()
|
||||
expect fun enumBenchmark()
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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.structsProducedByMacrosBenchmarks
|
||||
|
||||
expect fun macrosBenchmark()
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.typesBenchmarks
|
||||
|
||||
expect class StringBenchmark() {
|
||||
fun stringToCBenchmark()
|
||||
fun stringToKotlinBenchmark()
|
||||
}
|
||||
expect class IntBenchmark() {
|
||||
fun intBenchmark()
|
||||
}
|
||||
expect class BoxedIntBenchmark() {
|
||||
fun boxedIntBenchmark()
|
||||
}
|
||||
expect class IntMatrixBenchmark() {
|
||||
fun intMatrixBenchmark()
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package = org.jetbrains.structsProducedByMacrosBenchmarks
|
||||
|
||||
---
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define define_list(type) \
|
||||
\
|
||||
struct _list_##type; \
|
||||
\
|
||||
typedef struct \
|
||||
{ \
|
||||
int (*is_empty)(const struct _list_##type*); \
|
||||
size_t (*size)(const struct _list_##type*); \
|
||||
const type (*front)(const struct _list_##type*); \
|
||||
void (*push_front)(struct _list_##type*, type); \
|
||||
} _list_functions_##type; \
|
||||
\
|
||||
typedef struct _list_elem_##type \
|
||||
{ \
|
||||
type _data; \
|
||||
struct _list_elem_##type* _next; \
|
||||
} list_elem_##type; \
|
||||
\
|
||||
typedef struct _list_##type \
|
||||
{ \
|
||||
size_t _size; \
|
||||
list_elem_##type* _first; \
|
||||
list_elem_##type* _last; \
|
||||
_list_functions_##type* _functions; \
|
||||
} List_##type; \
|
||||
\
|
||||
List_##type* new_list_##type(); \
|
||||
int list_is_empty_##type(const List_##type* list); \
|
||||
size_t list_size_##type(const List_##type* list); \
|
||||
const type list_front_##type(const List_##type* list); \
|
||||
void list_push_front_##type(List_##type* list, type elem); \
|
||||
\
|
||||
int list_is_empty_##type(const List_##type* list) \
|
||||
{ \
|
||||
return list->_size == 0; \
|
||||
} \
|
||||
\
|
||||
size_t list_size_##type(const List_##type* list) \
|
||||
{ \
|
||||
return list->_size; \
|
||||
} \
|
||||
\
|
||||
const type list_front_##type(const List_##type* list) \
|
||||
{ \
|
||||
return list->_first->_data; \
|
||||
} \
|
||||
\
|
||||
void list_push_front_##type(List_##type* list, type elem) \
|
||||
{ \
|
||||
struct _list_elem_##type* element = (struct _list_elem_##type*) malloc(sizeof(struct _list_elem_##type)); \
|
||||
element->_data = elem; \
|
||||
element->_next = list->_first; \
|
||||
list->_first = element; \
|
||||
list->_size++; \
|
||||
} \
|
||||
\
|
||||
_list_functions_##type _list_funcs_##type = { \
|
||||
&list_is_empty_##type, \
|
||||
&list_size_##type, \
|
||||
&list_front_##type, \
|
||||
&list_push_front_##type, \
|
||||
}; \
|
||||
\
|
||||
List_##type* new_list_##type() \
|
||||
{ \
|
||||
List_##type* res = (List_##type*) malloc(sizeof(List_##type)); \
|
||||
res->_size = 0; \
|
||||
res->_first = NULL; \
|
||||
res->_functions = &_list_funcs_##type; \
|
||||
return res; \
|
||||
} \
|
||||
\
|
||||
void free_list_##type(List_##type* list) \
|
||||
{ \
|
||||
struct _list_elem_##type* current = list->_first; \
|
||||
while (current != NULL) \
|
||||
{ \
|
||||
struct _list_elem_##type* next = current->_next; \
|
||||
free(current); \
|
||||
current = next; \
|
||||
} \
|
||||
free(list); \
|
||||
}
|
||||
|
||||
|
||||
define_list(int)
|
||||
define_list(float)
|
||||
@@ -0,0 +1,97 @@
|
||||
package = org.jetbrains.structsBenchmarks
|
||||
strictEnums = WeekDay
|
||||
|
||||
---
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
enum WeekDay {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};
|
||||
|
||||
int isWeekEnd(enum WeekDay day) {
|
||||
if (day == Saturday || day == Sunday)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum WeekDay getWeekDay(const char* date) {
|
||||
if (strstr(date, "Sunday") != NULL) {
|
||||
return Sunday;
|
||||
} else if (strstr(date, "Monday") != NULL) {
|
||||
return Monday;
|
||||
} else if (strstr(date, "Tuesday") != NULL) {
|
||||
return Tuesday;
|
||||
} else if (strstr(date, "Wednesday") != NULL) {
|
||||
return Wednesday;
|
||||
} else if (strstr(date, "Thursday") != NULL) {
|
||||
return Thursday;
|
||||
} else if (strstr(date, "Friday") != NULL) {
|
||||
return Friday;
|
||||
} else if (strstr(date, "Saturday") != NULL) {
|
||||
return Saturday;
|
||||
}
|
||||
abort();
|
||||
}
|
||||
|
||||
struct ElementS {
|
||||
long long integer;
|
||||
float floatValue;
|
||||
char string[32];
|
||||
|
||||
int (*contains)(const struct ElementS*, const struct ElementS*);
|
||||
};
|
||||
|
||||
int elementContains(const struct ElementS* self, const struct ElementS* other) {
|
||||
if (self == NULL || other == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (strstr(self->string, other->string) != NULL) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
union ElementU {
|
||||
long long integer;
|
||||
float floatValue;
|
||||
char string[32];
|
||||
};
|
||||
|
||||
union ElementU multiplyElementU(union ElementU element, int coefficient) {
|
||||
union ElementU newElement;
|
||||
newElement.integer = coefficient * element.integer;
|
||||
return newElement;
|
||||
}
|
||||
|
||||
struct ElementS multiplyElementS(struct ElementS element, int coefficient) {
|
||||
struct ElementS newElement;
|
||||
newElement.integer = coefficient * element.integer;
|
||||
newElement.floatValue = coefficient * element.floatValue;
|
||||
int i = 0;
|
||||
while (element.string[i] != '\0') {
|
||||
newElement.string[i] = coefficient * element.string[i];
|
||||
i++;
|
||||
}
|
||||
return newElement;
|
||||
}
|
||||
|
||||
union ElementU* sumElementUPtr(const union ElementU* first, const union ElementU* second) {
|
||||
if (first == NULL || second == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
union ElementU* newElement = (union ElementU*)malloc(sizeof(union ElementU));
|
||||
newElement->integer = first->integer + second->integer;
|
||||
return newElement;
|
||||
}
|
||||
|
||||
struct ElementS* sumElementSPtr(const struct ElementS* first, const struct ElementS* second) {
|
||||
if (first == NULL || second == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
struct ElementS* newElement = (struct ElementS*)malloc(sizeof(struct ElementS));
|
||||
newElement->integer = first->integer + second->integer;
|
||||
newElement->floatValue = first->floatValue + second->floatValue;
|
||||
sprintf(newElement->string, "%d", newElement->integer);
|
||||
return newElement;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package = org.jetbrains.typesBenchmarks
|
||||
|
||||
---
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int charFrequency(const char* string, char charToFind) {
|
||||
int frequency = 0;
|
||||
for(int i = 0; string[i] != '\0'; ++i) {
|
||||
if(charToFind == string[i])
|
||||
++frequency;
|
||||
}
|
||||
return frequency;
|
||||
}
|
||||
|
||||
const char* findSuitableString(const char* stringsArray[], int arraySize, const char* stringToFind) {
|
||||
for(int i = 0; i < arraySize; ++i) {
|
||||
if (strstr(stringsArray[i], stringToFind) != NULL) {
|
||||
char* result = (char*) malloc((strlen(stringsArray[i])+1)*sizeof(char));
|
||||
strcpy(result, stringsArray[i]);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void freeSuitableString(char* unusedString) {
|
||||
free(unusedString);
|
||||
}
|
||||
|
||||
unsigned long int sum(int array[], int arraySize) {
|
||||
unsigned long int result = 0;
|
||||
for(int i = 0; i < arraySize; ++i) {
|
||||
result += array[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
double average(int count, ...) {
|
||||
va_list list;
|
||||
int j = 0;
|
||||
va_start(list, count);
|
||||
double sum = 0;
|
||||
for(j=0; j<count; j++) {
|
||||
sum += va_arg(list, int);
|
||||
}
|
||||
va_end(list);
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
int** multiplyMatrix(int m1, int m2, const int** mat1, int n1, int n2, const int** mat2) {
|
||||
int x, i, j;
|
||||
int **res = (int **)malloc(m1 * sizeof(int *));
|
||||
for (i=0; i<m1; i++) {
|
||||
res[i] = (int *)malloc(n2 * sizeof(int));
|
||||
}
|
||||
for (i = 0; i < m1; i++) {
|
||||
for (j = 0; j < n2; j++) {
|
||||
res[i][j] = 0;
|
||||
for (x = 0; x < m2; x++) {
|
||||
res[i][j] += mat1[i][x] * mat2[x][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import org.jetbrains.kotlin.MPPTools
|
||||
import org.jetbrains.kotlin.PlatformInfo
|
||||
import org.jetbrains.kotlin.RunJvmTask
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
|
||||
|
||||
buildscript {
|
||||
apply from: "$rootProject.projectDir/gradle/kotlinGradlePlugin.gradle"
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url 'https://cache-redirector.jetbrains.com/jcenter'
|
||||
}
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin-multiplatform'
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url 'https://cache-redirector.jetbrains.com/jcenter'
|
||||
}
|
||||
jcenter()
|
||||
maven {
|
||||
url kotlinCompilerRepo
|
||||
}
|
||||
maven {
|
||||
url buildKotlinCompilerRepo
|
||||
}
|
||||
}
|
||||
|
||||
def toolsPath = '../../tools'
|
||||
def frameworkName = 'benchmarksAnalyzer'
|
||||
|
||||
def buildType = NativeBuildType.valueOf(findProperty('nativeBuildType') ?: 'DEBUG')
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
macosMain {
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion"
|
||||
}
|
||||
kotlin.srcDir "$toolsPath/benchmarks/shared/src"
|
||||
kotlin.srcDir "$toolsPath/benchmarksAnalyzer/src/main/kotlin"
|
||||
kotlin.srcDir "$rootProject.projectDir/endorsedLibraries/kotlinx.cli/src/main/kotlin"
|
||||
kotlin.srcDir "$rootProject.projectDir/endorsedLibraries/kotlinx.cli/src/main/kotlin-native"
|
||||
kotlin.srcDir "$toolsPath/benchmarksAnalyzer/src/main/kotlin-native"
|
||||
}
|
||||
}
|
||||
|
||||
configure([macosX64("macos")]) {
|
||||
compilations.main.cinterops {
|
||||
libcurl {
|
||||
defFile "$toolsPath/benchmarksAnalyzer/src/nativeInterop/cinterop/libcurl.def"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macosX64("macos").binaries {
|
||||
framework(frameworkName, [buildType])
|
||||
}
|
||||
}
|
||||
|
||||
MPPTools.addTimeListener(project)
|
||||
|
||||
task konanRun {
|
||||
if (PlatformInfo.isMac()) {
|
||||
dependsOn 'build'
|
||||
}
|
||||
}
|
||||
|
||||
task jvmRun(type: RunJvmTask) {
|
||||
doLast {
|
||||
println("JVM run is unsupported")
|
||||
}
|
||||
}
|
||||
|
||||
def compilerFlags(def buildType) {
|
||||
def result = []
|
||||
if (buildType.optimized) {
|
||||
result.add("-opt")
|
||||
}
|
||||
if (buildType.debuggable) {
|
||||
result.add("-g")
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
task konanJsonReport {
|
||||
doLast {
|
||||
if (PlatformInfo.isMac()) {
|
||||
def applicationName = "FrameworkBenchmarksAnalyzer"
|
||||
def frameworkPath = kotlin.macosX64("macos").binaries.
|
||||
getFramework(frameworkName, kotlin.macosX64("macos").binaries.DEBUG).outputFile.absolutePath
|
||||
def nativeExecutable = new File("$frameworkPath/$frameworkName").canonicalPath
|
||||
def nativeCompileTime = MPPTools.getNativeCompileTime(project, applicationName, ['compileKotlinMacos',
|
||||
'linkBenchmarksAnalyzerDebugFrameworkMacos',
|
||||
'cinteropLibcurlMacos'])
|
||||
def properties = getCommonProperties() + ['type' : 'native',
|
||||
'compilerVersion': "${konanVersion}".toString(),
|
||||
'flags' : compilerFlags(buildType).sort(),
|
||||
'benchmarks' : '[]',
|
||||
'compileTime' : [nativeCompileTime],
|
||||
'codeSize' : MPPTools.getCodeSizeBenchmark(applicationName, nativeExecutable)]
|
||||
def output = MPPTools.createJsonReport(properties)
|
||||
new File("${buildDir.absolutePath}/${nativeJson}").write(output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task jvmJsonReport {
|
||||
doLast {
|
||||
println("JVM run is unsupported")
|
||||
}
|
||||
}
|
||||
|
||||
jvmRun.finalizedBy jvmJsonReport
|
||||
konanRun.finalizedBy konanJsonReport
|
||||
|
||||
private def getCommonProperties() {
|
||||
return ['cpu': System.getProperty("os.arch"),
|
||||
'os': System.getProperty("os.name"), // OperatingSystem.current().getName()
|
||||
'jdkVersion': System.getProperty("java.version"), // org.gradle.internal.jvm.Jvm.current().javaVersion
|
||||
'jdkVendor': System.getProperty("java.vendor"),
|
||||
'kotlinVersion': "${kotlinVersion}".toString()]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
kotlin.native.home=../../dist
|
||||
@@ -0,0 +1,21 @@
|
||||
kotlin.native.home=../dist
|
||||
org.jetbrains.kotlin.native.jvmArgs=-Xmx6G
|
||||
jvmWarmup = 1000
|
||||
nativeWarmup = 10
|
||||
attempts = 30
|
||||
jvmBenchResults = jvmBenchResults.json
|
||||
nativeBenchResults = nativeBenchResults.json
|
||||
nativeTextReport = nativeReport.txt
|
||||
jvmTextReport = jvmReport.txt
|
||||
nativeJson = nativeReport.json
|
||||
jvmJson = jvmReport.json
|
||||
analyzerTool = benchmarksAnalyzer
|
||||
analyzerToolDirectory = tools/benchmarksAnalyzer/build/bin
|
||||
outputReport = ../report/report.html
|
||||
artifactoryUrl = https://repo.labs.intellij.net
|
||||
artifactoryRepo = kotlin-native-benchmarks
|
||||
externalReports = coroutinesReport.txt
|
||||
externalBenchmarksReport = externalReport.json
|
||||
|
||||
# Avoid building platform libraries by the MPP plugin.
|
||||
kotlin.native.distribution.type=prebuilt
|
||||
@@ -0,0 +1,75 @@
|
||||
import org.jetbrains.kotlin.MPPTools
|
||||
|
||||
def exitCodes = [:]
|
||||
|
||||
MPPTools.addTimeListener(project)
|
||||
|
||||
|
||||
task konanRun {
|
||||
dependsOn "configureBuild"
|
||||
(1..project.ext.repeatNumber).each { number ->
|
||||
project.ext.buildSteps.keySet().each {
|
||||
dependsOn "$it$number"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task configureBuild {
|
||||
doLast {
|
||||
mkdir "${buildDir.absolutePath}"
|
||||
}
|
||||
}
|
||||
|
||||
(1..project.ext.repeatNumber).each { number ->
|
||||
project.ext.buildSteps.each { taskName, command ->
|
||||
tasks.create(name: "$taskName$number", type: Exec) {
|
||||
commandLine command
|
||||
ignoreExitValue true
|
||||
doLast {
|
||||
exitCodes[name] = execResult.exitValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task clean {
|
||||
doLast {
|
||||
delete "${buildDir.absolutePath}"
|
||||
}
|
||||
}
|
||||
|
||||
task konanJsonReport {
|
||||
doLast {
|
||||
def nativeCompileTime = MPPTools.getCompileBenchmarkTime(project.ext.applicationName, project.ext.buildSteps.keySet(),
|
||||
project.ext.repeatNumber, exitCodes)
|
||||
def nativeExecutable = "${buildDir.absolutePath}/program${MPPTools.getNativeProgramExtension()}"
|
||||
def properties = getCommonProperties() + ['type': 'native',
|
||||
'compilerVersion': "${konanVersion}".toString(),
|
||||
'benchmarks': "[]",
|
||||
'compileTime': nativeCompileTime,
|
||||
'codeSize': MPPTools.getCodeSizeBenchmark(project.ext.applicationName, nativeExecutable) ]
|
||||
def output = MPPTools.createJsonReport(properties)
|
||||
new File("${buildDir.absolutePath}/${nativeJson}").write(output)
|
||||
}
|
||||
}
|
||||
task jvmRun {
|
||||
println("JVM run isn't supported")
|
||||
}
|
||||
|
||||
task jvmJsonReport {
|
||||
doLast {
|
||||
println("JVM run isn't supported")
|
||||
}
|
||||
}
|
||||
|
||||
jvmRun.finalizedBy jvmJsonReport
|
||||
konanRun.finalizedBy konanJsonReport
|
||||
|
||||
private def getCommonProperties() {
|
||||
return ['cpu': System.getProperty("os.arch"),
|
||||
'os': System.getProperty("os.name"), // OperatingSystem.current().getName()
|
||||
'jdkVersion': System.getProperty("java.version"), // org.gradle.internal.jvm.Jvm.current().javaVersion
|
||||
'jdkVendor': System.getProperty("java.vendor"),
|
||||
'kotlinVersion': "${kotlinVersion}".toString()]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import org.jetbrains.kotlin.getNativeProgramExtension
|
||||
import org.jetbrains.kotlin.getCompileOnlyBenchmarksOpts
|
||||
|
||||
plugins {
|
||||
id("compile-benchmarking")
|
||||
}
|
||||
|
||||
val dist = file(findProperty("kotlin.native.home") ?: "dist")
|
||||
val toolSuffix = if (System.getProperty("os.name").startsWith("Windows")) ".bat" else ""
|
||||
val binarySuffix = getNativeProgramExtension()
|
||||
val defaultCompilerOpts = listOf("-g")
|
||||
val buildOpts = getCompileOnlyBenchmarksOpts(project, defaultCompilerOpts)
|
||||
|
||||
compileBenchmark {
|
||||
applicationName = "HelloWorld"
|
||||
repeatNumber = 10
|
||||
compilerOpts = buildOpts
|
||||
buildSteps {
|
||||
step("runKonanc") {
|
||||
command("$dist/bin/konanc$toolSuffix", "$projectDir/src/main/kotlin/main.kt", "-o",
|
||||
"$buildDir/program$binarySuffix", *(buildOpts.toTypedArray()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
kotlin.native.home=../../dist
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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.
|
||||
*/
|
||||
|
||||
fun main() {
|
||||
println("Hello, World!")
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import org.jetbrains.kotlin.benchmark.BenchmarkingPlugin
|
||||
import org.jetbrains.kotlin.ExecClang
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
|
||||
plugins {
|
||||
id("benchmarking")
|
||||
}
|
||||
|
||||
val defaultBuildType = NativeBuildType.RELEASE
|
||||
|
||||
benchmark {
|
||||
applicationName = "Numerical"
|
||||
commonSrcDirs = listOf("src/main/kotlin", "../../tools/benchmarks/shared/src/main/kotlin/report", "../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("../shared/src/main/kotlin-native/mingw")
|
||||
posixSrcDirs = listOf("../shared/src/main/kotlin-native/posix")
|
||||
linkerOpts = listOf("$buildDir/pi.o")
|
||||
buildType = (findProperty("nativeBuildType") as String?)?.let { NativeBuildType.valueOf(it) } ?: defaultBuildType
|
||||
|
||||
dependencies.common(project(":endorsedLibraries:kotlinx.cli"))
|
||||
}
|
||||
|
||||
val compileLibary by tasks.creating {
|
||||
doFirst {
|
||||
mkdir(buildDir)
|
||||
|
||||
project.withConvention(ExecClang::class) {
|
||||
execKonanClang(HostManager.host) {
|
||||
args("-O3")
|
||||
args("-c", "$projectDir/src/nativeInterop/cinterop/pi.c")
|
||||
args("-o", "$buildDir/pi.o")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val native = kotlin.targets.getByName("native") as KotlinNativeTarget
|
||||
native.apply {
|
||||
compilations["main"].cinterops {
|
||||
create("cinterop") {
|
||||
headers("$projectDir/src/nativeInterop/cinterop/pi.h")
|
||||
}
|
||||
}
|
||||
binaries.getExecutable(BenchmarkingPlugin.NATIVE_EXECUTABLE_NAME, "RELEASE").linkTask.dependsOn(compileLibary)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
kotlin.native.home=../../dist
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the licenses/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import org.jetbrains.benchmarksLauncher.*
|
||||
|
||||
actual class NumericalLauncher : Launcher() {
|
||||
override val benchmarks = BenchmarksCollection(
|
||||
mutableMapOf(
|
||||
"BellardPi" to BenchmarkEntry(::jvmBellardPi)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun jvmBellardPi() {
|
||||
for (n in 1 .. 1000 step 9) {
|
||||
val result = pi_nth_digit(n)
|
||||
Blackhole.consume(result)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the licenses/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import org.jetbrains.benchmarksLauncher.*
|
||||
|
||||
actual class NumericalLauncher : Launcher() {
|
||||
override val benchmarks = BenchmarksCollection(
|
||||
mutableMapOf(
|
||||
"BellardPi" to BenchmarkEntry(::konanBellardPi),
|
||||
"BellardPiCinterop" to BenchmarkEntry(::clangBellardPi)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun konanBellardPi() {
|
||||
for (n in 1 .. 1000 step 9) {
|
||||
val result = pi_nth_digit(n)
|
||||
Blackhole.consume(result)
|
||||
}
|
||||
}
|
||||
|
||||
fun clangBellardPi() {
|
||||
for (n in 1 .. 1000 step 9)
|
||||
cinterop.pi_nth_digit(n)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the licenses/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import org.jetbrains.benchmarksLauncher.*
|
||||
import kotlinx.cli.*
|
||||
|
||||
expect class NumericalLauncher() : Launcher {
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val launcher = NumericalLauncher()
|
||||
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,152 @@
|
||||
/*
|
||||
* Computation of the n'th decimal digit of \pi with very little memory.
|
||||
* Written by Fabrice Bellard on January 8, 1997.
|
||||
*
|
||||
* We use a slightly modified version of the method described by Simon
|
||||
* Plouffe in "On the Computation of the n'th decimal digit of various
|
||||
* transcendental numbers" (November 1996). We have modified the algorithm
|
||||
* to get a running time of O(n^2) instead of O(n^3log(n)^3).
|
||||
*/
|
||||
|
||||
import kotlin.math.ln
|
||||
import kotlin.math.sqrt
|
||||
|
||||
private fun mul_mod(a: Int, b: Int, m: Int)
|
||||
= ((a.toLong() * b.toLong()) % m).toInt()
|
||||
|
||||
/* return the inverse of x mod y */
|
||||
private fun inv_mod(x: Int, y: Int): Int {
|
||||
var u = x
|
||||
var v = y
|
||||
var c = 1
|
||||
var a = 0
|
||||
do {
|
||||
val q = v / u
|
||||
var t = c
|
||||
c = a - q * c
|
||||
a = t
|
||||
t = u
|
||||
u = v - q * u
|
||||
v = t
|
||||
} while (u != 0)
|
||||
a = a % y
|
||||
if (a < 0)
|
||||
a = y + a
|
||||
return a
|
||||
}
|
||||
|
||||
/* return (a^b) mod m */
|
||||
private fun pow_mod(a: Int, b: Int, m: Int): Int {
|
||||
var b = b
|
||||
var r = 1
|
||||
var aa = a
|
||||
while (true) {
|
||||
if (b and 1 != 0)
|
||||
r = mul_mod(r, aa, m)
|
||||
b = b shr 1
|
||||
if (b == 0)
|
||||
break
|
||||
aa = mul_mod(aa, aa, m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
/* return true if n is prime */
|
||||
private fun is_prime(n: Int): Boolean {
|
||||
if (n % 2 == 0)
|
||||
return false
|
||||
val r = sqrt(n.toDouble()).toInt()
|
||||
var i = 3
|
||||
while (i <= r) {
|
||||
if (n % i == 0)
|
||||
return false
|
||||
i += 2
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/* return the prime number immediatly after n */
|
||||
private fun next_prime(n: Int): Int {
|
||||
var n = n
|
||||
do {
|
||||
n++
|
||||
} while (!is_prime(n))
|
||||
return n
|
||||
}
|
||||
|
||||
fun pi_nth_digit(n: Int): Int {
|
||||
|
||||
val N = ((n + 20) * ln(10.0) / ln(2.0)).toInt()
|
||||
var sum = 0.0
|
||||
var a = 3
|
||||
var t: Int
|
||||
|
||||
while (a <= 2 * N) {
|
||||
|
||||
val vmax = (ln((2 * N).toDouble()) / ln(a.toDouble())).toInt()
|
||||
var av = 1
|
||||
var i = 0
|
||||
while (i < vmax) {
|
||||
av = av * a
|
||||
i++
|
||||
}
|
||||
|
||||
var s = 0
|
||||
var num = 1
|
||||
var den = 1
|
||||
var v = 0
|
||||
var kq = 1
|
||||
var kq2 = 1
|
||||
|
||||
var k = 1
|
||||
while (k <= N) {
|
||||
|
||||
t = k
|
||||
if (kq >= a) {
|
||||
do {
|
||||
t = t / a
|
||||
v--
|
||||
} while (t % a == 0)
|
||||
kq = 0
|
||||
}
|
||||
kq++
|
||||
num = mul_mod(num, t, av)
|
||||
|
||||
t = 2 * k - 1
|
||||
if (kq2 >= a) {
|
||||
if (kq2 == a) {
|
||||
do {
|
||||
t = t / a
|
||||
v++
|
||||
} while (t % a == 0)
|
||||
}
|
||||
kq2 -= a
|
||||
}
|
||||
den = mul_mod(den, t, av)
|
||||
kq2 += 2
|
||||
|
||||
if (v > 0) {
|
||||
t = inv_mod(den, av)
|
||||
t = mul_mod(t, num, av)
|
||||
t = mul_mod(t, k, av)
|
||||
i = v
|
||||
while (i < vmax) {
|
||||
t = mul_mod(t, a, av)
|
||||
i++
|
||||
}
|
||||
s += t
|
||||
if (s >= av)
|
||||
s -= av
|
||||
}
|
||||
k++
|
||||
|
||||
}
|
||||
|
||||
t = pow_mod(10, n - 1, av)
|
||||
s = mul_mod(s, t, av)
|
||||
sum = (sum + s.toDouble() / av.toDouble()) % 1.0
|
||||
a = next_prime(a)
|
||||
}
|
||||
|
||||
return (sum * 1e9).toInt()
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package = cinterop
|
||||
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Computation of the n'th decimal digit of \pi with very little memory.
|
||||
* Written by Fabrice Bellard on January 8, 1997.
|
||||
*
|
||||
* We use a slightly modified version of the method described by Simon
|
||||
* Plouffe in "On the Computation of the n'th decimal digit of various
|
||||
* transcendental numbers" (November 1996). We have modified the algorithm
|
||||
* to get a running time of O(n^2) instead of O(n^3log(n)^3).
|
||||
*
|
||||
* This program uses mostly integer arithmetic. It may be slow on some
|
||||
* hardwares where integer multiplications and divisons must be done
|
||||
* by software. We have supposed that 'int' has a size of 32 bits. If
|
||||
* your compiler supports 'long long' integers of 64 bits, you may use
|
||||
* the integer version of 'mul_mod' (see HAS_LONG_LONG).
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/* uncomment the following line to use 'long long' integers */
|
||||
#define HAS_LONG_LONG
|
||||
|
||||
#ifdef HAS_LONG_LONG
|
||||
#define mul_mod(a,b,m) (( (long long) (a) * (long long) (b) ) % (m))
|
||||
#else
|
||||
#define mul_mod(a,b,m) fmod( (double) a * (double) b, m)
|
||||
#endif
|
||||
|
||||
/* return the inverse of x mod y */
|
||||
static int inv_mod(int x, int y)
|
||||
{
|
||||
int q, u, v, a, c, t;
|
||||
|
||||
u = x;
|
||||
v = y;
|
||||
c = 1;
|
||||
a = 0;
|
||||
do {
|
||||
q = v / u;
|
||||
|
||||
t = c;
|
||||
c = a - q * c;
|
||||
a = t;
|
||||
|
||||
t = u;
|
||||
u = v - q * u;
|
||||
v = t;
|
||||
} while (u != 0);
|
||||
a = a % y;
|
||||
if (a < 0)
|
||||
a = y + a;
|
||||
return a;
|
||||
}
|
||||
|
||||
/* return (a^b) mod m */
|
||||
static int pow_mod(int a, int b, int m)
|
||||
{
|
||||
int r, aa;
|
||||
|
||||
r = 1;
|
||||
aa = a;
|
||||
while (1) {
|
||||
if (b & 1)
|
||||
r = mul_mod(r, aa, m);
|
||||
b = b >> 1;
|
||||
if (b == 0)
|
||||
break;
|
||||
aa = mul_mod(aa, aa, m);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/* return true if n is prime */
|
||||
static int is_prime(int n)
|
||||
{
|
||||
int r, i;
|
||||
if ((n % 2) == 0)
|
||||
return 0;
|
||||
|
||||
r = (int) (sqrt(n));
|
||||
for (i = 3; i <= r; i += 2)
|
||||
if ((n % i) == 0)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* return the prime number immediatly after n */
|
||||
static int next_prime(int n)
|
||||
{
|
||||
do {
|
||||
n++;
|
||||
} while (!is_prime(n));
|
||||
return n;
|
||||
}
|
||||
|
||||
int pi_nth_digit(int n)
|
||||
{
|
||||
int av, a, vmax, N, num, den, k, kq, kq2, t, v, s, i;
|
||||
double sum;
|
||||
|
||||
N = (int) ((n + 20) * log(10) / log(2));
|
||||
|
||||
sum = 0;
|
||||
|
||||
for (a = 3; a <= (2 * N); a = next_prime(a)) {
|
||||
|
||||
vmax = (int) (log(2 * N) / log(a));
|
||||
av = 1;
|
||||
for (i = 0; i < vmax; i++)
|
||||
av = av * a;
|
||||
|
||||
s = 0;
|
||||
num = 1;
|
||||
den = 1;
|
||||
v = 0;
|
||||
kq = 1;
|
||||
kq2 = 1;
|
||||
|
||||
for (k = 1; k <= N; k++) {
|
||||
|
||||
t = k;
|
||||
if (kq >= a) {
|
||||
do {
|
||||
t = t / a;
|
||||
v--;
|
||||
} while ((t % a) == 0);
|
||||
kq = 0;
|
||||
}
|
||||
kq++;
|
||||
num = mul_mod(num, t, av);
|
||||
|
||||
t = (2 * k - 1);
|
||||
if (kq2 >= a) {
|
||||
if (kq2 == a) {
|
||||
do {
|
||||
t = t / a;
|
||||
v++;
|
||||
} while ((t % a) == 0);
|
||||
}
|
||||
kq2 -= a;
|
||||
}
|
||||
den = mul_mod(den, t, av);
|
||||
kq2 += 2;
|
||||
|
||||
if (v > 0) {
|
||||
t = inv_mod(den, av);
|
||||
t = mul_mod(t, num, av);
|
||||
t = mul_mod(t, k, av);
|
||||
for (i = v; i < vmax; i++)
|
||||
t = mul_mod(t, a, av);
|
||||
s += t;
|
||||
if (s >= av)
|
||||
s -= av;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
t = pow_mod(10, n - 1, av);
|
||||
s = mul_mod(s, t, av);
|
||||
sum = fmod(sum + (double) s / (double) av, 1.0);
|
||||
}
|
||||
|
||||
return (int) (sum * 1e9);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Computation of the n'th decimal digit of \pi with very little memory.
|
||||
* Written by Fabrice Bellard on January 8, 1997.
|
||||
*
|
||||
* We use a slightly modified version of the method described by Simon
|
||||
* Plouffe in "On the Computation of the n'th decimal digit of various
|
||||
* transcendental numbers" (November 1996). We have modified the algorithm
|
||||
* to get a running time of O(n^2) instead of O(n^3log(n)^3).
|
||||
*/
|
||||
|
||||
#ifndef _BELLARD_PI_H
|
||||
#define _BELLARD_PI_H
|
||||
|
||||
int pi_nth_digit(int n);
|
||||
|
||||
#endif /*_BELLARD_PI_H*/
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import org.jetbrains.kotlin.benchmark.BenchmarkingPlugin
|
||||
import org.jetbrains.kotlin.ExecClang
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
|
||||
plugins {
|
||||
id("benchmarking")
|
||||
}
|
||||
|
||||
val defaultBuildType = NativeBuildType.RELEASE
|
||||
|
||||
benchmark {
|
||||
applicationName = "ObjCInterop"
|
||||
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")
|
||||
linkerOpts = listOf("-L$buildDir", "-lcomplexnumbers")
|
||||
buildType = (findProperty("nativeBuildType") as String?)?.let { NativeBuildType.valueOf(it) } ?: defaultBuildType
|
||||
|
||||
dependencies.common(project(":endorsedLibraries:kotlinx.cli"))
|
||||
}
|
||||
|
||||
val compileLibary by tasks.creating {
|
||||
doFirst {
|
||||
mkdir(buildDir)
|
||||
|
||||
project.withConvention(ExecClang::class) {
|
||||
execKonanClang(HostManager.host) {
|
||||
args("$projectDir/src/nativeInterop/cinterop/complexNumbers.m")
|
||||
args("-lobjc", "-fobjc-arc")
|
||||
args("-fPIC", "-shared", "-o", "$buildDir/libcomplexnumbers.dylib")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val native = kotlin.targets.getByName("native") as KotlinNativeTarget
|
||||
native.apply {
|
||||
compilations["main"].cinterops {
|
||||
create("classes") {
|
||||
headers("$projectDir/src/nativeInterop/cinterop/complexNumbers.h")
|
||||
}
|
||||
}
|
||||
binaries.getExecutable(BenchmarkingPlugin.NATIVE_EXECUTABLE_NAME, "RELEASE").linkTask.dependsOn(compileLibary)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
kotlin.native.home=../../dist
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package org.jetbrains.complexNumbers
|
||||
|
||||
actual class ComplexNumber() {}
|
||||
|
||||
actual class ComplexNumbersBenchmark actual constructor() {
|
||||
actual fun generateNumbersSequence(): List<ComplexNumber> {
|
||||
error("Benchmark generateNumbersSequence is unsupported on JVM!")
|
||||
}
|
||||
|
||||
actual fun sumComplex() {
|
||||
error("Benchmark sumComplex is unsupported on JVM!")
|
||||
}
|
||||
|
||||
actual fun subComplex() {
|
||||
error("Benchmark subComplex is unsupported on JVM!")
|
||||
}
|
||||
actual fun classInheritance() {
|
||||
error("Benchmark classInheritance is unsupported on JVM!")
|
||||
}
|
||||
actual fun categoryMethods() {
|
||||
error("Benchmark categoryMethods is unsupported on JVM!")
|
||||
}
|
||||
actual fun stringToObjC() {
|
||||
error("Benchmark stringToObjC is unsupported on JVM!")
|
||||
}
|
||||
actual fun stringFromObjC() {
|
||||
error("Benchmark stringToObjC is unsupported on JVM!")
|
||||
}
|
||||
actual fun fft() {
|
||||
error("Benchmark fft is unsupported on JVM!")
|
||||
}
|
||||
actual fun invertFft() {
|
||||
error("Benchmark invertFft is unsupported on JVM!")
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.complexNumbers
|
||||
import kotlinx.cinterop.*
|
||||
import platform.posix.*
|
||||
import kotlin.math.sqrt
|
||||
import kotlin.math.PI
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
import kotlin.random.Random
|
||||
import platform.Foundation.*
|
||||
import platform.darwin.*
|
||||
|
||||
actual typealias ComplexNumber = Complex
|
||||
|
||||
actual class ComplexNumbersBenchmark actual constructor() {
|
||||
val complexNumbersSequence = generateNumbersSequence()
|
||||
|
||||
fun randomNumber() = Random.nextDouble(0.0, benchmarkSize.toDouble())
|
||||
|
||||
actual fun generateNumbersSequence(): List<Complex> {
|
||||
val result = mutableListOf<Complex>()
|
||||
for (i in 1..benchmarkSize) {
|
||||
result.add(Complex(randomNumber(), randomNumber()))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
actual fun sumComplex() {
|
||||
complexNumbersSequence.map { it.add(it) }.reduce { acc, it -> acc.add(it) }
|
||||
}
|
||||
|
||||
actual fun subComplex() {
|
||||
complexNumbersSequence.map { it.sub(it) }.reduce { acc, it -> acc.sub(it) }
|
||||
}
|
||||
|
||||
actual fun classInheritance() {
|
||||
class InvertedNumber(val value: Double) : CustomNumberProtocol, NSObject() {
|
||||
override fun add(other: CustomNumberProtocol) : CustomNumberProtocol =
|
||||
if (other is InvertedNumber)
|
||||
InvertedNumber(-value + sqrt(other.value))
|
||||
else
|
||||
error("Expected object of InvertedNumber class")
|
||||
|
||||
|
||||
override fun sub(other: CustomNumberProtocol) : CustomNumberProtocol =
|
||||
if (other is InvertedNumber)
|
||||
InvertedNumber(-value - sqrt(other.value))
|
||||
else
|
||||
error("Expected object of InvertedNumber class")
|
||||
}
|
||||
|
||||
val result = InvertedNumber(0.0)
|
||||
|
||||
for (i in 1..benchmarkSize) {
|
||||
result.add(InvertedNumber(randomNumber()))
|
||||
result.sub(InvertedNumber(randomNumber()))
|
||||
}
|
||||
}
|
||||
|
||||
actual fun categoryMethods() {
|
||||
complexNumbersSequence.map { it.mul(it) }.reduce { acc, it -> acc.mul(it) }
|
||||
complexNumbersSequence.map { it.div(it) }.reduce { acc, it -> acc.mul(it) }
|
||||
}
|
||||
|
||||
actual fun stringToObjC() {
|
||||
complexNumbersSequence.forEach {
|
||||
it.setFormat("%.1lf|%.1lf")
|
||||
}
|
||||
}
|
||||
|
||||
actual fun stringFromObjC() {
|
||||
complexNumbersSequence.forEach {
|
||||
it.description()?.split(" ")
|
||||
}
|
||||
}
|
||||
|
||||
private fun revert(number: Int, lg: Int): Int {
|
||||
var result = 0
|
||||
for (i in 0 until lg) {
|
||||
if (number and (1 shl i) != 0) {
|
||||
result = result or 1 shl (lg - i - 1)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
inline private fun fftRoutine(invert:Boolean = false): Array<Complex> {
|
||||
var lg = 0
|
||||
while ((1 shl lg) < complexNumbersSequence.size) {
|
||||
lg++
|
||||
}
|
||||
val sequence = complexNumbersSequence.toTypedArray()
|
||||
|
||||
sequence.forEachIndexed { index, number ->
|
||||
if (index < revert(index, lg) && revert(index, lg) < complexNumbersSequence.size) {
|
||||
sequence[index] = sequence[revert(index, lg)].also { sequence[revert(index, lg)] = sequence[index] }
|
||||
}
|
||||
}
|
||||
|
||||
var length = 2
|
||||
while (length < complexNumbersSequence.size) {
|
||||
val angle = 2 * PI / length * if (invert) -1 else 1
|
||||
val base = Complex(cos(angle), sin(angle))
|
||||
for (i in 0 until complexNumbersSequence.size / 2 step length) {
|
||||
var value = Complex(1.0, 1.0)
|
||||
for (j in 0 until length/2) {
|
||||
val first = sequence[i + j]
|
||||
val second = sequence[i + j + length/2].mul(value)
|
||||
sequence[i + j] = first.add(second) as Complex
|
||||
sequence[i + j + length/2] = first.sub(second) as Complex
|
||||
value = value.mul(base)
|
||||
}
|
||||
}
|
||||
length = length shl 1
|
||||
}
|
||||
return sequence
|
||||
}
|
||||
|
||||
actual fun fft() {
|
||||
fftRoutine()
|
||||
}
|
||||
|
||||
actual fun invertFft() {
|
||||
val sequence = fftRoutine(true)
|
||||
|
||||
sequence.forEachIndexed { index, number ->
|
||||
sequence[index] = number.div(Complex(sequence.size.toDouble(), 0.0))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
import org.jetbrains.benchmarksLauncher.*
|
||||
import org.jetbrains.complexNumbers.*
|
||||
import kotlinx.cli.*
|
||||
|
||||
class ObjCInteropLauncher: Launcher() {
|
||||
override val benchmarks = BenchmarksCollection(
|
||||
mutableMapOf(
|
||||
"generateNumbersSequence" to BenchmarkEntryWithInit.create(::ComplexNumbersBenchmark, { generateNumbersSequence() }),
|
||||
"sumComplex" to BenchmarkEntryWithInit.create(::ComplexNumbersBenchmark, { sumComplex() }),
|
||||
"subComplex" to BenchmarkEntryWithInit.create(::ComplexNumbersBenchmark, { subComplex() }),
|
||||
"classInheritance" to BenchmarkEntryWithInit.create(::ComplexNumbersBenchmark, { classInheritance() }),
|
||||
"categoryMethods" to BenchmarkEntryWithInit.create(::ComplexNumbersBenchmark, { categoryMethods() }),
|
||||
"stringToObjC" to BenchmarkEntryWithInit.create(::ComplexNumbersBenchmark, { stringToObjC() }),
|
||||
"stringFromObjC" to BenchmarkEntryWithInit.create(::ComplexNumbersBenchmark, { stringFromObjC() }),
|
||||
"fft" to BenchmarkEntryWithInit.create(::ComplexNumbersBenchmark, { fft() }),
|
||||
"invertFft" to BenchmarkEntryWithInit.create(::ComplexNumbersBenchmark, { invertFft() })
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val launcher = ObjCInteropLauncher()
|
||||
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)
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.complexNumbers
|
||||
|
||||
const val benchmarkSize = 10000
|
||||
|
||||
expect class ComplexNumber
|
||||
|
||||
expect class ComplexNumbersBenchmark() {
|
||||
fun generateNumbersSequence(): List<ComplexNumber>
|
||||
fun sumComplex()
|
||||
fun subComplex()
|
||||
fun classInheritance()
|
||||
fun categoryMethods()
|
||||
fun stringToObjC()
|
||||
fun stringFromObjC()
|
||||
fun fft()
|
||||
fun invertFft()
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
package = org.jetbrains.complexNumbers
|
||||
language = Objective-C
|
||||
@@ -0,0 +1,22 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@protocol CustomNumber
|
||||
@required
|
||||
- (id<CustomNumber> _Nonnull)add: (id<CustomNumber> _Nonnull)other;
|
||||
- (id<CustomNumber> _Nonnull)sub: (id<CustomNumber> _Nonnull)other;
|
||||
@end
|
||||
|
||||
@interface Complex : NSObject<CustomNumber>
|
||||
|
||||
@property (nonatomic, readonly) double re;
|
||||
@property (nonatomic, readonly) double im;
|
||||
@property (nonatomic, readwrite) NSString *format;
|
||||
|
||||
- (id)initWithRe: (double)re andIm: (double)im;
|
||||
+ (Complex *)complexWithRe: (double)re im: (double)im;
|
||||
@end
|
||||
|
||||
@interface Complex (CategorizedComplex)
|
||||
- (Complex * _Nonnull)mul: (Complex * _Nonnull)other;
|
||||
- (Complex * _Nonnull)div: (Complex * _Nonnull)other;
|
||||
@end
|
||||
@@ -0,0 +1,62 @@
|
||||
#import <stdio.h>
|
||||
#import "complexNumbers.h"
|
||||
|
||||
@implementation Complex
|
||||
{
|
||||
double re;
|
||||
double im;
|
||||
NSString *format;
|
||||
}
|
||||
- (id)init {
|
||||
return [self initWithRe: 0.0 andIm: 0.0];
|
||||
}
|
||||
|
||||
- (id)initWithRe: (double)_re andIm: (double)_im {
|
||||
if (self = [super init]) {
|
||||
re = _re;
|
||||
im = _im;
|
||||
format = @"re: %.1lf im: %.1lf";
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (Complex *)complexWithRe: (double)re im: (double)im {
|
||||
return [[Complex alloc] initWithRe: re andIm: im];
|
||||
}
|
||||
- (id<CustomNumber> _Nonnull)add: (id<CustomNumber> _Nonnull)other {
|
||||
if ([self isKindOfClass:[Complex class]]) {
|
||||
Complex * otherComplex = (Complex *)other;
|
||||
return [[Complex alloc] initWithRe: re + otherComplex->re andIm: im + otherComplex->im];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
- (id<CustomNumber> _Nonnull)sub: (id<CustomNumber> _Nonnull)other {
|
||||
if ([self isKindOfClass:[Complex class]]) {
|
||||
Complex * otherComplex = (Complex *)other;
|
||||
return [[Complex alloc] initWithRe: re - otherComplex->re andIm: im - otherComplex->im];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
- (NSString *)description {
|
||||
return [NSString stringWithFormat: format, re, im];
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation Complex (CategorizedComplex)
|
||||
- (Complex * _Nonnull)mul: (Complex * _Nonnull)other {
|
||||
return [Complex complexWithRe: re * other.re - im * other.im im: re * other.im + im * other.re];
|
||||
}
|
||||
- (Complex * _Nonnull)div: (Complex * _Nonnull)other {
|
||||
double retRe;
|
||||
double retIm;
|
||||
double denominator;
|
||||
denominator = other.re * other.re + other.im * other.im;
|
||||
if (!denominator)
|
||||
return nil;
|
||||
retRe = (re * other.re + im * other.im) / denominator;
|
||||
retIm = (im * other.re - re * other.im) / denominator;
|
||||
return [Complex complexWithRe: retRe im: retIm];
|
||||
}
|
||||
@end
|
||||
@@ -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)
|
||||
}
|
||||
+52
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
+25
@@ -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
|
||||
}
|
||||
}
|
||||
+106
@@ -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 }
|
||||
// }
|
||||
}
|
||||
+79
@@ -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
|
||||
}
|
||||
}
|
||||
+136
@@ -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 }
|
||||
}
|
||||
}
|
||||
+103
@@ -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 }
|
||||
}
|
||||
}
|
||||
+30
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
+350
@@ -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
|
||||
}
|
||||
|
||||
+82
@@ -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)
|
||||
}
|
||||
}
|
||||
+86
@@ -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
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user