Move everything under kotlin-native folder
I was forced to manually do update the following files, because otherwise they would be ignored according .gitignore settings. Probably they should be deleted from repo. Interop/.idea/compiler.xml Interop/.idea/gradle.xml Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml Interop/.idea/modules.xml Interop/.idea/modules/Indexer/Indexer.iml Interop/.idea/modules/Runtime/Runtime.iml Interop/.idea/modules/StubGenerator/StubGenerator.iml backend.native/backend.native.iml backend.native/bc.frontend/bc.frontend.iml backend.native/cli.bc/cli.bc.iml backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt backend.native/tests/link/lib/foo.kt backend.native/tests/link/lib/foo2.kt backend.native/tests/teamcity-test.property
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
package org.jetbrains.complexNumbers
|
||||
|
||||
actual class ComplexNumber() {}
|
||||
|
||||
actual class ComplexNumbersBenchmark actual constructor() {
|
||||
actual fun generateNumbersSequence(): List<ComplexNumber> {
|
||||
error("Benchmark generateNumbersSequence is unsupported on JVM!")
|
||||
}
|
||||
|
||||
actual fun sumComplex() {
|
||||
error("Benchmark sumComplex is unsupported on JVM!")
|
||||
}
|
||||
|
||||
actual fun subComplex() {
|
||||
error("Benchmark subComplex is unsupported on JVM!")
|
||||
}
|
||||
actual fun classInheritance() {
|
||||
error("Benchmark classInheritance is unsupported on JVM!")
|
||||
}
|
||||
actual fun categoryMethods() {
|
||||
error("Benchmark categoryMethods is unsupported on JVM!")
|
||||
}
|
||||
actual fun stringToObjC() {
|
||||
error("Benchmark stringToObjC is unsupported on JVM!")
|
||||
}
|
||||
actual fun stringFromObjC() {
|
||||
error("Benchmark stringToObjC is unsupported on JVM!")
|
||||
}
|
||||
actual fun fft() {
|
||||
error("Benchmark fft is unsupported on JVM!")
|
||||
}
|
||||
actual fun invertFft() {
|
||||
error("Benchmark invertFft is unsupported on JVM!")
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.complexNumbers
|
||||
import kotlinx.cinterop.*
|
||||
import platform.posix.*
|
||||
import kotlin.math.sqrt
|
||||
import kotlin.math.PI
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
import kotlin.random.Random
|
||||
import platform.Foundation.*
|
||||
import platform.darwin.*
|
||||
|
||||
actual typealias ComplexNumber = Complex
|
||||
|
||||
actual class ComplexNumbersBenchmark actual constructor() {
|
||||
val complexNumbersSequence = generateNumbersSequence()
|
||||
|
||||
fun randomNumber() = Random.nextDouble(0.0, benchmarkSize.toDouble())
|
||||
|
||||
actual fun generateNumbersSequence(): List<Complex> {
|
||||
val result = mutableListOf<Complex>()
|
||||
for (i in 1..benchmarkSize) {
|
||||
result.add(Complex(randomNumber(), randomNumber()))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
actual fun sumComplex() {
|
||||
complexNumbersSequence.map { it.add(it) }.reduce { acc, it -> acc.add(it) }
|
||||
}
|
||||
|
||||
actual fun subComplex() {
|
||||
complexNumbersSequence.map { it.sub(it) }.reduce { acc, it -> acc.sub(it) }
|
||||
}
|
||||
|
||||
actual fun classInheritance() {
|
||||
class InvertedNumber(val value: Double) : CustomNumberProtocol, NSObject() {
|
||||
override fun add(other: CustomNumberProtocol) : CustomNumberProtocol =
|
||||
if (other is InvertedNumber)
|
||||
InvertedNumber(-value + sqrt(other.value))
|
||||
else
|
||||
error("Expected object of InvertedNumber class")
|
||||
|
||||
|
||||
override fun sub(other: CustomNumberProtocol) : CustomNumberProtocol =
|
||||
if (other is InvertedNumber)
|
||||
InvertedNumber(-value - sqrt(other.value))
|
||||
else
|
||||
error("Expected object of InvertedNumber class")
|
||||
}
|
||||
|
||||
val result = InvertedNumber(0.0)
|
||||
|
||||
for (i in 1..benchmarkSize) {
|
||||
result.add(InvertedNumber(randomNumber()))
|
||||
result.sub(InvertedNumber(randomNumber()))
|
||||
}
|
||||
}
|
||||
|
||||
actual fun categoryMethods() {
|
||||
complexNumbersSequence.map { it.mul(it) }.reduce { acc, it -> acc.mul(it) }
|
||||
complexNumbersSequence.map { it.div(it) }.reduce { acc, it -> acc.mul(it) }
|
||||
}
|
||||
|
||||
actual fun stringToObjC() {
|
||||
complexNumbersSequence.forEach {
|
||||
it.setFormat("%.1lf|%.1lf")
|
||||
}
|
||||
}
|
||||
|
||||
actual fun stringFromObjC() {
|
||||
complexNumbersSequence.forEach {
|
||||
it.description()?.split(" ")
|
||||
}
|
||||
}
|
||||
|
||||
private fun revert(number: Int, lg: Int): Int {
|
||||
var result = 0
|
||||
for (i in 0 until lg) {
|
||||
if (number and (1 shl i) != 0) {
|
||||
result = result or 1 shl (lg - i - 1)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
inline private fun fftRoutine(invert:Boolean = false): Array<Complex> {
|
||||
var lg = 0
|
||||
while ((1 shl lg) < complexNumbersSequence.size) {
|
||||
lg++
|
||||
}
|
||||
val sequence = complexNumbersSequence.toTypedArray()
|
||||
|
||||
sequence.forEachIndexed { index, number ->
|
||||
if (index < revert(index, lg) && revert(index, lg) < complexNumbersSequence.size) {
|
||||
sequence[index] = sequence[revert(index, lg)].also { sequence[revert(index, lg)] = sequence[index] }
|
||||
}
|
||||
}
|
||||
|
||||
var length = 2
|
||||
while (length < complexNumbersSequence.size) {
|
||||
val angle = 2 * PI / length * if (invert) -1 else 1
|
||||
val base = Complex(cos(angle), sin(angle))
|
||||
for (i in 0 until complexNumbersSequence.size / 2 step length) {
|
||||
var value = Complex(1.0, 1.0)
|
||||
for (j in 0 until length/2) {
|
||||
val first = sequence[i + j]
|
||||
val second = sequence[i + j + length/2].mul(value)
|
||||
sequence[i + j] = first.add(second) as Complex
|
||||
sequence[i + j + length/2] = first.sub(second) as Complex
|
||||
value = value.mul(base)
|
||||
}
|
||||
}
|
||||
length = length shl 1
|
||||
}
|
||||
return sequence
|
||||
}
|
||||
|
||||
actual fun fft() {
|
||||
fftRoutine()
|
||||
}
|
||||
|
||||
actual fun invertFft() {
|
||||
val sequence = fftRoutine(true)
|
||||
|
||||
sequence.forEachIndexed { index, number ->
|
||||
sequence[index] = number.div(Complex(sequence.size.toDouble(), 0.0))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
import org.jetbrains.benchmarksLauncher.*
|
||||
import org.jetbrains.complexNumbers.*
|
||||
import kotlinx.cli.*
|
||||
|
||||
class ObjCInteropLauncher: Launcher() {
|
||||
override val benchmarks = BenchmarksCollection(
|
||||
mutableMapOf(
|
||||
"generateNumbersSequence" to BenchmarkEntryWithInit.create(::ComplexNumbersBenchmark, { generateNumbersSequence() }),
|
||||
"sumComplex" to BenchmarkEntryWithInit.create(::ComplexNumbersBenchmark, { sumComplex() }),
|
||||
"subComplex" to BenchmarkEntryWithInit.create(::ComplexNumbersBenchmark, { subComplex() }),
|
||||
"classInheritance" to BenchmarkEntryWithInit.create(::ComplexNumbersBenchmark, { classInheritance() }),
|
||||
"categoryMethods" to BenchmarkEntryWithInit.create(::ComplexNumbersBenchmark, { categoryMethods() }),
|
||||
"stringToObjC" to BenchmarkEntryWithInit.create(::ComplexNumbersBenchmark, { stringToObjC() }),
|
||||
"stringFromObjC" to BenchmarkEntryWithInit.create(::ComplexNumbersBenchmark, { stringFromObjC() }),
|
||||
"fft" to BenchmarkEntryWithInit.create(::ComplexNumbersBenchmark, { fft() }),
|
||||
"invertFft" to BenchmarkEntryWithInit.create(::ComplexNumbersBenchmark, { invertFft() })
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val launcher = ObjCInteropLauncher()
|
||||
BenchmarksRunner.runBenchmarks(args, { arguments: BenchmarkArguments ->
|
||||
if (arguments is BaseBenchmarkArguments) {
|
||||
launcher.launch(arguments.warmup, arguments.repeat, arguments.prefix,
|
||||
arguments.filter, arguments.filterRegex, arguments.verbose)
|
||||
} else emptyList()
|
||||
}, benchmarksListAction = launcher::benchmarksListAction)
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.complexNumbers
|
||||
|
||||
const val benchmarkSize = 10000
|
||||
|
||||
expect class ComplexNumber
|
||||
|
||||
expect class ComplexNumbersBenchmark() {
|
||||
fun generateNumbersSequence(): List<ComplexNumber>
|
||||
fun sumComplex()
|
||||
fun subComplex()
|
||||
fun classInheritance()
|
||||
fun categoryMethods()
|
||||
fun stringToObjC()
|
||||
fun stringFromObjC()
|
||||
fun fft()
|
||||
fun invertFft()
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
package = org.jetbrains.complexNumbers
|
||||
language = Objective-C
|
||||
@@ -0,0 +1,22 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@protocol CustomNumber
|
||||
@required
|
||||
- (id<CustomNumber> _Nonnull)add: (id<CustomNumber> _Nonnull)other;
|
||||
- (id<CustomNumber> _Nonnull)sub: (id<CustomNumber> _Nonnull)other;
|
||||
@end
|
||||
|
||||
@interface Complex : NSObject<CustomNumber>
|
||||
|
||||
@property (nonatomic, readonly) double re;
|
||||
@property (nonatomic, readonly) double im;
|
||||
@property (nonatomic, readwrite) NSString *format;
|
||||
|
||||
- (id)initWithRe: (double)re andIm: (double)im;
|
||||
+ (Complex *)complexWithRe: (double)re im: (double)im;
|
||||
@end
|
||||
|
||||
@interface Complex (CategorizedComplex)
|
||||
- (Complex * _Nonnull)mul: (Complex * _Nonnull)other;
|
||||
- (Complex * _Nonnull)div: (Complex * _Nonnull)other;
|
||||
@end
|
||||
@@ -0,0 +1,62 @@
|
||||
#import <stdio.h>
|
||||
#import "complexNumbers.h"
|
||||
|
||||
@implementation Complex
|
||||
{
|
||||
double re;
|
||||
double im;
|
||||
NSString *format;
|
||||
}
|
||||
- (id)init {
|
||||
return [self initWithRe: 0.0 andIm: 0.0];
|
||||
}
|
||||
|
||||
- (id)initWithRe: (double)_re andIm: (double)_im {
|
||||
if (self = [super init]) {
|
||||
re = _re;
|
||||
im = _im;
|
||||
format = @"re: %.1lf im: %.1lf";
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (Complex *)complexWithRe: (double)re im: (double)im {
|
||||
return [[Complex alloc] initWithRe: re andIm: im];
|
||||
}
|
||||
- (id<CustomNumber> _Nonnull)add: (id<CustomNumber> _Nonnull)other {
|
||||
if ([self isKindOfClass:[Complex class]]) {
|
||||
Complex * otherComplex = (Complex *)other;
|
||||
return [[Complex alloc] initWithRe: re + otherComplex->re andIm: im + otherComplex->im];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
- (id<CustomNumber> _Nonnull)sub: (id<CustomNumber> _Nonnull)other {
|
||||
if ([self isKindOfClass:[Complex class]]) {
|
||||
Complex * otherComplex = (Complex *)other;
|
||||
return [[Complex alloc] initWithRe: re - otherComplex->re andIm: im - otherComplex->im];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
- (NSString *)description {
|
||||
return [NSString stringWithFormat: format, re, im];
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation Complex (CategorizedComplex)
|
||||
- (Complex * _Nonnull)mul: (Complex * _Nonnull)other {
|
||||
return [Complex complexWithRe: re * other.re - im * other.im im: re * other.im + im * other.re];
|
||||
}
|
||||
- (Complex * _Nonnull)div: (Complex * _Nonnull)other {
|
||||
double retRe;
|
||||
double retIm;
|
||||
double denominator;
|
||||
denominator = other.re * other.re + other.im * other.im;
|
||||
if (!denominator)
|
||||
return nil;
|
||||
retRe = (re * other.re + im * other.im) / denominator;
|
||||
retIm = (im * other.re - re * other.im) / denominator;
|
||||
return [Complex complexWithRe: retRe im: retIm];
|
||||
}
|
||||
@end
|
||||
Reference in New Issue
Block a user