Added some swift benchmarks (#3419)
This commit is contained in:
@@ -11,8 +11,6 @@ import org.gradle.api.Task
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.api.tasks.options.Option
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||
import javax.inject.Inject
|
||||
import java.io.File
|
||||
|
||||
open class RunJvmTask : JavaExec() {
|
||||
@@ -49,4 +47,4 @@ open class RunJvmTask : JavaExec() {
|
||||
else
|
||||
executeTask()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,11 +53,11 @@ internal val Project.jvmJson: String
|
||||
|
||||
internal val Project.commonBenchmarkProperties: Map<String, Any>
|
||||
get() = mapOf(
|
||||
"cpu" to System.getProperty("os.arch"),
|
||||
"os" to System.getProperty("os.name"),
|
||||
"jdkVersion" to System.getProperty("java.version"),
|
||||
"jdkVendor" to System.getProperty("java.vendor"),
|
||||
"kotlinVersion" to kotlinVersion
|
||||
"cpu" to System.getProperty("os.arch"),
|
||||
"os" to System.getProperty("os.name"),
|
||||
"jdkVersion" to System.getProperty("java.version"),
|
||||
"jdkVendor" to System.getProperty("java.vendor"),
|
||||
"kotlinVersion" to kotlinVersion
|
||||
)
|
||||
|
||||
open class BenchmarkExtension @Inject constructor(val project: Project) {
|
||||
@@ -70,7 +70,7 @@ open class BenchmarkExtension @Inject constructor(val project: Project) {
|
||||
val dependencies: BenchmarkDependencies = BenchmarkDependencies()
|
||||
|
||||
fun dependencies(action: BenchmarkDependencies.() -> Unit) =
|
||||
dependencies.action()
|
||||
dependencies.action()
|
||||
|
||||
fun dependencies(action: Closure<*>) {
|
||||
ConfigureUtil.configure(action, dependencies)
|
||||
@@ -83,7 +83,7 @@ open class BenchmarkExtension @Inject constructor(val project: Project) {
|
||||
fun project(path: String): Dependency = project.dependencies.project(mapOf("path" to path))
|
||||
|
||||
fun project(path: String, configuration: String): Dependency =
|
||||
project.dependencies.project(mapOf("path" to path, "configuration" to configuration))
|
||||
project.dependencies.project(mapOf("path" to path, "configuration" to configuration))
|
||||
|
||||
fun common(notation: Any) = sourceSets.commonMain.dependencies {
|
||||
implementation(notation)
|
||||
@@ -108,9 +108,9 @@ abstract class BenchmarkingPlugin: Plugin<Project> {
|
||||
protected val mingwPath: String = System.getenv("MINGW64_DIR") ?: "c:/msys64/mingw64"
|
||||
|
||||
protected open fun Project.determinePreset(): AbstractKotlinNativeTargetPreset<*> =
|
||||
defaultHostPreset(this).also { preset ->
|
||||
logger.quiet("$project has been configured for ${preset.name} platform.")
|
||||
} as AbstractKotlinNativeTargetPreset<*>
|
||||
defaultHostPreset(this).also { preset ->
|
||||
logger.quiet("$project has been configured for ${preset.name} platform.")
|
||||
} as AbstractKotlinNativeTargetPreset<*>
|
||||
|
||||
protected abstract fun NamedDomainObjectContainer<KotlinSourceSet>.configureSources(project: Project)
|
||||
|
||||
@@ -193,7 +193,7 @@ abstract class BenchmarkingPlugin: Plugin<Project> {
|
||||
nativeTarget.compilations.main.kotlinOptions.freeCompilerArgs.map { "\"$it\"" }
|
||||
|
||||
protected open fun Project.collectCodeSize(applicationName: String) =
|
||||
getCodeSizeBenchmark(applicationName, nativeExecutable)
|
||||
getCodeSizeBenchmark(applicationName, nativeExecutable)
|
||||
|
||||
protected open fun Project.configureKonanJsonTask(nativeTarget: KotlinNativeTarget): Task {
|
||||
return tasks.create("konanJsonReport") {
|
||||
@@ -204,7 +204,7 @@ abstract class BenchmarkingPlugin: Plugin<Project> {
|
||||
val applicationName = benchmark.applicationName
|
||||
val benchContents = buildDir.resolve(nativeBenchResults).readText()
|
||||
val nativeCompileTime = if (benchmark.compileTasks.isEmpty()) getNativeCompileTime(applicationName)
|
||||
else getNativeCompileTime(applicationName, benchmark.compileTasks)
|
||||
else getNativeCompileTime(applicationName, benchmark.compileTasks)
|
||||
|
||||
val properties = commonBenchmarkProperties + mapOf(
|
||||
"type" to "native",
|
||||
@@ -258,4 +258,4 @@ abstract class BenchmarkingPlugin: Plugin<Project> {
|
||||
const val NATIVE_EXECUTABLE_NAME = "benchmark"
|
||||
const val BENCHMARKING_GROUP = "benchmarking"
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-3
@@ -83,7 +83,7 @@ open class SwiftBenchmarkingPlugin : BenchmarkingPlugin() {
|
||||
task.dependsOn(framework.linkTaskName)
|
||||
task.doLast {
|
||||
val frameworkParentDirPath = framework.outputDirectory.absolutePath
|
||||
val options = listOf("-Xlinker", "-rpath", "-Xlinker", frameworkParentDirPath, "-F", frameworkParentDirPath)
|
||||
val options = listOf("-O", "-wmo", "-Xlinker", "-rpath", "-Xlinker", frameworkParentDirPath, "-F", frameworkParentDirPath)
|
||||
compileSwift(project, nativeTarget.konanTarget, benchmark.swiftSources, options,
|
||||
Paths.get(buildDir.absolutePath, benchmark.applicationName), false)
|
||||
}
|
||||
@@ -99,5 +99,9 @@ open class SwiftBenchmarkingPlugin : BenchmarkingPlugin() {
|
||||
)
|
||||
|
||||
override fun Project.getCompilerFlags(nativeTarget: KotlinNativeTarget) =
|
||||
listOf<String>()
|
||||
}
|
||||
if (benchmark.useCodeSize == CodeSizeEntity.FRAMEWORK) {
|
||||
nativeTarget.compilations.main.kotlinOptions.freeCompilerArgs.map { "\"$it\"" }
|
||||
} else {
|
||||
listOf("-O", "-wmo")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
buildscript {
|
||||
apply from: "$rootProject.projectDir/gradle/kotlinGradlePlugin.gradle"
|
||||
repositories {
|
||||
maven {
|
||||
url 'https://cache-redirector.jetbrains.com/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)
|
||||
uploadBenchmarkResultToBintray(nativeJson)
|
||||
}
|
||||
}
|
||||
|
||||
task mergeJvmReports {
|
||||
doLast {
|
||||
mergeReports(jvmJson)
|
||||
uploadBenchmarkResultToBintray(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 @@
|
||||
org.jetbrains.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
|
||||
}
|
||||
}
|
||||
@@ -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(size: Int32(CommandLine.arguments.count - 1), init: {index in
|
||||
CommandLine.arguments[Int(truncating: index) + 1]
|
||||
})
|
||||
|
||||
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] = ["-де",
|
||||
"-ка",
|
||||
"-либо",
|
||||
"-нибудь",
|
||||
"-с",
|
||||
"-таки",
|
||||
"-то",
|
||||
"а",
|
||||
"а-конто",
|
||||
"а-ля",
|
||||
"аба",
|
||||
"абажур",
|
||||
"абажурный",
|
||||
"абаз",
|
||||
"абазин",
|
||||
"абазинец",
|
||||
"абазинка",
|
||||
"абазинский",
|
||||
"абак",
|
||||
"абака",
|
||||
"аббат",
|
||||
"аббатиса",
|
||||
"аббатский",
|
||||
"аббатство",
|
||||
"аббревиатура",
|
||||
"аббревиатурный",
|
||||
"аббревиация",
|
||||
"абдикация",
|
||||
"абдомен",
|
||||
"абдоминальный",
|
||||
"абдуктор",
|
||||
"абдукторный",
|
||||
"абдукция",
|
||||
"абелит",
|
||||
"аберрационный",
|
||||
"аберрация",
|
||||
"абзац",
|
||||
"абзацный",
|
||||
"абиетин",
|
||||
"абиетиновый",
|
||||
"абиссальный",
|
||||
"абиссинец",
|
||||
"абиссинский",
|
||||
"абитуриент",
|
||||
"абитуриентка",
|
||||
"абитуриентский",
|
||||
"аблактировать",
|
||||
"аблактировка",
|
||||
"аблятив",
|
||||
"абляут",
|
||||
"абляция",
|
||||
"аболиционизм",
|
||||
"аболиционист",
|
||||
"аболиционистский",
|
||||
"аболиция",
|
||||
"абонемент",
|
||||
"абонементный",
|
||||
"абонент",
|
||||
"абонентка",
|
||||
"абонентный",
|
||||
"абонентский",
|
||||
"абонирование",
|
||||
"абонировать",
|
||||
"абонироваться",
|
||||
"абордаж",
|
||||
"абордажный",
|
||||
"абордировать",
|
||||
"абориген",
|
||||
"аборигенный",
|
||||
"аборт",
|
||||
"абортарий",
|
||||
"абортивный",
|
||||
"абортировать",
|
||||
"абразив",
|
||||
"абразивный",
|
||||
"абразионный",
|
||||
"абразия",
|
||||
"абракадабра",
|
||||
"абреже",
|
||||
"абрек",
|
||||
"абрикос",
|
||||
"абрикосный",
|
||||
"абрикосовка",
|
||||
"абрикосовый",
|
||||
"абрикотин",
|
||||
"абрис",
|
||||
"абрисный",
|
||||
"абсент",
|
||||
"абсентеизм",
|
||||
"абсентеист",
|
||||
"абсолют",
|
||||
"абсолютивный",
|
||||
"абсолютизирование",
|
||||
"абсолютизировать",
|
||||
"абсолютизм",
|
||||
"абсолютист",
|
||||
"абсолютистский",
|
||||
"абсолютность",
|
||||
"абсолютный",
|
||||
"абсолюция",
|
||||
"абсорбент",
|
||||
"абсорбер",
|
||||
"абсорбировать",
|
||||
"абсорбционный",
|
||||
"абсорбция",
|
||||
"абстинент",
|
||||
"абстрагирование",
|
||||
"абстрагировать",
|
||||
"абстрагироваться",
|
||||
"абстракт",
|
||||
"абстрактность",
|
||||
"абстрактный",
|
||||
"абстракционизм",
|
||||
"абстракционист",
|
||||
"абстракционистский",
|
||||
"абстракция",
|
||||
"абсурд",
|
||||
"абсурдность",
|
||||
"абсурдный",
|
||||
"абсцесс",
|
||||
"абсцисса",
|
||||
"абулия",
|
||||
"абхаз",
|
||||
"абхазец",
|
||||
"абхазка",
|
||||
"абхазский",
|
||||
"абцуг",
|
||||
"абштрих",
|
||||
"абъюрация",
|
||||
"абы",
|
||||
"авалист",
|
||||
"аваль",
|
||||
"авангард",
|
||||
"авангардизм",
|
||||
"авангардист",
|
||||
"авангардистский",
|
||||
"авангардный",
|
||||
"аванзал",
|
||||
"аванзальный",
|
||||
"аванкамера",
|
||||
"аванложа",
|
||||
"аванпорт",
|
||||
"аванпост",
|
||||
"аванпостный",
|
||||
"аванс",
|
||||
"авансирование",
|
||||
"авансировать",
|
||||
"авансовый",
|
||||
"авансом",
|
||||
"авансцена",
|
||||
"авантаж",
|
||||
"авантажный",
|
||||
"авантюра",
|
||||
"авантюризм",
|
||||
"авантюрин",
|
||||
"авантюриновый",
|
||||
"авантюрист",
|
||||
"авантюристический",
|
||||
"авантюристичный",
|
||||
"авантюристка",
|
||||
"авантюристский",
|
||||
"авантюрность",
|
||||
"авантюрный",
|
||||
"авар",
|
||||
"аварец",
|
||||
"аварийность",
|
||||
"аварийный",
|
||||
"аварийщик",
|
||||
"авария",
|
||||
"аварка",
|
||||
"аварский",
|
||||
"авгиев",
|
||||
"авгит",
|
||||
"авгур",
|
||||
"август",
|
||||
"августейший",
|
||||
"августинец",
|
||||
"августовский",
|
||||
"авдотка",
|
||||
"авеню",
|
||||
"аверс",
|
||||
"авестийский",
|
||||
"авиабаза",
|
||||
"авиабензин",
|
||||
"авиагоризонт",
|
||||
"авиадвигатель",
|
||||
"авиадесант",
|
||||
"авиадесантный",
|
||||
"авиазавод",
|
||||
"авиаконструктор",
|
||||
"авиалиния",
|
||||
"авиаматка",
|
||||
"авиамоделизм",
|
||||
"авиамоделист",
|
||||
"авиамодель",
|
||||
"авиамодельный",
|
||||
"авиамотор",
|
||||
"авиамоторный",
|
||||
"авианосец",
|
||||
"авиапочта",
|
||||
"авиаприбор",
|
||||
"авиапромышленность",
|
||||
"авиапромышленный",
|
||||
"авиаразведка",
|
||||
"авиастроение",
|
||||
"авиастроитель",
|
||||
"авиастроительный",
|
||||
"авиастроительство",
|
||||
"авиасъёмка",
|
||||
"авиатехник",
|
||||
"авиатор",
|
||||
"авиаторский",
|
||||
"авиатранспорт",
|
||||
"авиатранспортный",
|
||||
"авиатрасса",
|
||||
"авиационный",
|
||||
"авиация",
|
||||
"авиачасть",
|
||||
"авиашкола",
|
||||
"авиетка",
|
||||
"авизировать",
|
||||
"авизный",
|
||||
"авизо",
|
||||
"авитаминоз",
|
||||
"авитаминозный",
|
||||
"авифауна",
|
||||
"авокадо",
|
||||
"авось",
|
||||
"авоська",
|
||||
"аврал",
|
||||
"авралить",
|
||||
"авральный",
|
||||
"авран",
|
||||
"аврора",
|
||||
"австралиец",
|
||||
"австралийка",
|
||||
"австралийский",
|
||||
"австралопитек",
|
||||
"австриец",
|
||||
"австрийка",
|
||||
"австрийский",
|
||||
"австрияк",
|
||||
"австриячка",
|
||||
"австро-венгерский",
|
||||
"автаркический",
|
||||
"автаркия",
|
||||
"авто",
|
||||
"автобаза",
|
||||
"автобиографический",
|
||||
"автобиографичность",
|
||||
"автобиографичный",
|
||||
"автобиография",
|
||||
"автоблокировка",
|
||||
"автоблокировочный",
|
||||
"автобус",
|
||||
"автобусник",
|
||||
"автобусный",
|
||||
"автовакцина",
|
||||
"автовесы",
|
||||
"автовокзал",
|
||||
"автогамия",
|
||||
"автоген",
|
||||
"автогенез",
|
||||
"автогенератор",
|
||||
"автогенный",
|
||||
"автогенщик",
|
||||
"автогипноз",
|
||||
"автогонки",
|
||||
"автогравюра",
|
||||
"автограф",
|
||||
"автографический",
|
||||
"автография",
|
||||
"автогужевой",
|
||||
"автодидакт",
|
||||
"автодоение",
|
||||
"автодорожник",
|
||||
"автодорожный",
|
||||
"автодрезина",
|
||||
"автодром",
|
||||
"автожир",
|
||||
"автозавод",
|
||||
"автозаводец",
|
||||
"автозаводский",
|
||||
"автозаводской",
|
||||
"автозаправочный",
|
||||
"автозаправщик",
|
||||
"автоинспектор",
|
||||
"автоинспекция",
|
||||
"автокар",
|
||||
"автокара",
|
||||
"автокатализ",
|
||||
"автокефалия",
|
||||
"автокефальный",
|
||||
"автоклав",
|
||||
"автоклуб",
|
||||
"автоколонна",
|
||||
"автокомбинат",
|
||||
"автокран",
|
||||
"автократ",
|
||||
"автократический",
|
||||
"автократия",
|
||||
"автокружок",
|
||||
"автол",
|
||||
"автолавка",
|
||||
"автолиз",
|
||||
"автолитография",
|
||||
"автолюбитель",
|
||||
"автолюбительство",
|
||||
"автомагистраль",
|
||||
"автомат",
|
||||
"автоматизация",
|
||||
"автоматизирование",
|
||||
"автоматизировать",
|
||||
"автоматизироваться",
|
||||
"автоматизм",
|
||||
"автоматика",
|
||||
"автоматический",
|
||||
"автоматичность",
|
||||
"автоматичный",
|
||||
"автоматный",
|
||||
"автоматчик",
|
||||
"автоматчица",
|
||||
"автомашина",
|
||||
"автомашинист",
|
||||
"автомеханик",
|
||||
"автомобилестроение",
|
||||
"автомобилестроитель",
|
||||
"автомобилестроительный",
|
||||
"автомобилизация",
|
||||
"автомобилизм",
|
||||
"автомобилист",
|
||||
"автомобилистка",
|
||||
"автомобиль",
|
||||
"автомобильный",
|
||||
"автомобильчик",
|
||||
"автоморфизм",
|
||||
"автомотоклуб",
|
||||
"автомоторный",
|
||||
"автомотошкола",
|
||||
"автомотриса",
|
||||
"автономист",
|
||||
"автономистский",
|
||||
"автономический",
|
||||
"автономия",
|
||||
"автономность",
|
||||
"автономный",
|
||||
"автопарк",
|
||||
"автоперевозка",
|
||||
"автопилот",
|
||||
"автопластика",
|
||||
"автоплуг",
|
||||
"автопогрузчик",
|
||||
"автоподъёмник",
|
||||
"автопоезд",
|
||||
"автопоилка",
|
||||
"автопокрышка",
|
||||
"автопортрет",
|
||||
"автопробег",
|
||||
"автопромышленность",
|
||||
"автор",
|
||||
"авторалли",
|
||||
"авторегулятор",
|
||||
"авторемонтник",
|
||||
"авторемонтный",
|
||||
"автореферат",
|
||||
"авторефрижератор",
|
||||
"авторизация",
|
||||
"авторизованный",
|
||||
"авторизовать",
|
||||
"авторитарность",
|
||||
"авторитарный",
|
||||
"авторитет",
|
||||
"авторитетность",
|
||||
"авторитетный",
|
||||
"авторота",
|
||||
"авторские",
|
||||
"авторский",
|
||||
"авторство",
|
||||
"авторулевой",
|
||||
"авторучка",
|
||||
"автосани",
|
||||
"автосборка",
|
||||
"автосварщик",
|
||||
"автоспорт",
|
||||
"автостанция",
|
||||
"автостоп",
|
||||
"автострада",
|
||||
"автостроение",
|
||||
"автостроитель",
|
||||
"автосцепка",
|
||||
"автотележка",
|
||||
"автотип",
|
||||
"автотипический",
|
||||
"автотипия",
|
||||
"автотипный",
|
||||
"автотомия",
|
||||
"автотормоз",
|
||||
"автотормозной",
|
||||
"автотракторный",
|
||||
"автотранспорт",
|
||||
"автотранспортный",
|
||||
"автотрансформатор",
|
||||
"автотрасса",
|
||||
"автотуризм",
|
||||
"автотурист",
|
||||
"автоукладчик",
|
||||
"автофургон",
|
||||
"автохозяйство",
|
||||
"автохром",
|
||||
"автохромный",
|
||||
"автохтон",
|
||||
"автохтонный",
|
||||
"автоцистерна",
|
||||
"авточасть",
|
||||
"автошкола",
|
||||
"автоштурман",
|
||||
"авуары",
|
||||
"ага",
|
||||
"ага-хан",
|
||||
"агава",
|
||||
"агалит",
|
||||
"агальматолит",
|
||||
"агама",
|
||||
"агами",
|
||||
"агамия",
|
||||
"агамогония",
|
||||
"агар-агар",
|
||||
"агарный",
|
||||
"агаровый",
|
||||
"агарянин",
|
||||
"агат",
|
||||
"агатный",
|
||||
"агатовый",
|
||||
"агглютинативность",
|
||||
"агглютинативный",
|
||||
"агглютинация",
|
||||
"агглютинин",
|
||||
"агглютинирующий",
|
||||
"аггравация",
|
||||
"агент",
|
||||
"агентский",
|
||||
"агентство",
|
||||
"агентура",
|
||||
"агентурный",
|
||||
"агиографический",
|
||||
"агиография",
|
||||
"агиология",
|
||||
"агитатор",
|
||||
"агитаторский",
|
||||
"агитаторша",
|
||||
"агитационный",
|
||||
"агитация",
|
||||
"агитбригада",
|
||||
"агитировать",
|
||||
"агитка",
|
||||
"агиткампания",
|
||||
"агитмассовый",
|
||||
"агитпоезд",
|
||||
"агитпроп",
|
||||
"агитпункт",
|
||||
"аглицкий",
|
||||
"агломерат",
|
||||
"агломератчик",
|
||||
"агломерационный",
|
||||
"агломерация",
|
||||
"агломерировать",
|
||||
"агломерироваться",
|
||||
"агнат",
|
||||
"агнец",
|
||||
"агнозия",
|
||||
"агностик",
|
||||
"агностицизм",
|
||||
"агностический",
|
||||
"агонизировать",
|
||||
"агонический",
|
||||
"агония",
|
||||
"агорафобия",
|
||||
"аграмант",
|
||||
"аграмантовый",
|
||||
"аграрий",
|
||||
"аграрник",
|
||||
"аграрный",
|
||||
"аграф",
|
||||
"аграфия",
|
||||
"агрегат",
|
||||
"агрегатный",
|
||||
"агреман",
|
||||
"агрессивность",
|
||||
"агрессивный",
|
||||
"агрессия",
|
||||
"агрессор",
|
||||
"агрикультура",
|
||||
"агрикультурный",
|
||||
"агробаза",
|
||||
"агробиолог",
|
||||
"агробиологический",
|
||||
"агробиология",
|
||||
"агроботаника",
|
||||
"агрозоотехника",
|
||||
"агромелиорация"
|
||||
]
|
||||
@@ -228,4 +228,9 @@ task swiftinterop {
|
||||
task videoplayer {
|
||||
dependsOn 'clean'
|
||||
dependsOn 'videoplayer:konanRun'
|
||||
}
|
||||
|
||||
task KotlinVsSwift {
|
||||
dependsOn 'clean'
|
||||
dependsOn 'KotlinVsSwift:konanRun'
|
||||
}
|
||||
@@ -70,7 +70,6 @@ class RingLauncher : Launcher() {
|
||||
"ClassStream.countFiltered" to BenchmarkEntryWithInit.create(::ClassStreamBenchmark, { countFiltered() }),
|
||||
"ClassStream.reduce" to BenchmarkEntryWithInit.create(::ClassStreamBenchmark, { reduce() }),
|
||||
"CompanionObject.invokeRegularFunction" to BenchmarkEntryWithInit.create(::CompanionObjectBenchmark, { invokeRegularFunction() }),
|
||||
"CompanionObject.invokeJvmStaticFunction" to BenchmarkEntryWithInit.create(::CompanionObjectBenchmark, { invokeJvmStaticFunction() }),
|
||||
"DefaultArgument.testOneOfTwo" to BenchmarkEntryWithInit.create(::DefaultArgumentBenchmark, { testOneOfTwo() }),
|
||||
"DefaultArgument.testTwoOfTwo" to BenchmarkEntryWithInit.create(::DefaultArgumentBenchmark, { testTwoOfTwo() }),
|
||||
"DefaultArgument.testOneOfFour" to BenchmarkEntryWithInit.create(::DefaultArgumentBenchmark, { testOneOfFour() }),
|
||||
|
||||
@@ -22,18 +22,9 @@ open class CompanionObjectBenchmark {
|
||||
regularCompanionObjectFunction("")
|
||||
}
|
||||
|
||||
//Benchmark
|
||||
fun invokeJvmStaticFunction() {
|
||||
staticCompanionObjectFunction("")
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun regularCompanionObjectFunction(o: Any): Any {
|
||||
return o
|
||||
}
|
||||
|
||||
fun staticCompanionObjectFunction(o: Any): Any {
|
||||
return o
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -155,7 +155,6 @@ open class EulerBenchmark {
|
||||
|
||||
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
|
||||
|
||||
@@ -8,6 +8,7 @@ plugins {
|
||||
}
|
||||
|
||||
val toolsPath = "../../tools"
|
||||
val targetExtension = "Macos"
|
||||
|
||||
swiftBenchmark {
|
||||
applicationName = "swiftInterop"
|
||||
|
||||
@@ -41,6 +41,10 @@ include ':performance:framework'
|
||||
if (System.getProperty("os.name") == "Mac OS X") {
|
||||
include ':performance:objcinterop'
|
||||
include ':performance:swiftinterop'
|
||||
if (hasProperty("runExcludedBenchmarks")) {
|
||||
include ':performance:KotlinVsSwift'
|
||||
include ':performance:KotlinVsSwift:ring'
|
||||
}
|
||||
}
|
||||
|
||||
include ':platformLibs'
|
||||
|
||||
Reference in New Issue
Block a user