From 62dfd528e3d1f96febd2e6e2d92ba8511530cb29 Mon Sep 17 00:00:00 2001 From: Elena Lepilkina Date: Tue, 28 Sep 2021 11:49:25 +0300 Subject: [PATCH] [K/N][perf] Added benchmarks for unsigned arrays for-loops --- .../performance/ring/src/main/kotlin/main.kt | 6 ++ .../org/jetbrains/ring/ForLoopsBenchmark.kt | 60 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/kotlin-native/performance/ring/src/main/kotlin/main.kt b/kotlin-native/performance/ring/src/main/kotlin/main.kt index 952fac5fbee..2c4997cbdf9 100644 --- a/kotlin-native/performance/ring/src/main/kotlin/main.kt +++ b/kotlin-native/performance/ring/src/main/kotlin/main.kt @@ -96,11 +96,17 @@ class RingLauncher : Launcher() { "ForLoops.floatArrayLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { floatArrayLoop() }), "ForLoops.charArrayLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { charArrayLoop() }), "ForLoops.stringLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { stringLoop() }), + "ForLoops.uIntArrayLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { uIntArrayLoop() }), + "ForLoops.uShortArrayLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { uShortArrayLoop() }), + "ForLoops.uLongArrayLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { uLongArrayLoop() }), "ForLoops.arrayIndicesLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { arrayIndicesLoop() }), "ForLoops.intArrayIndicesLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { intArrayIndicesLoop() }), "ForLoops.floatArrayIndicesLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { floatArrayIndicesLoop() }), "ForLoops.charArrayIndicesLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { charArrayIndicesLoop() }), "ForLoops.stringIndicesLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { stringIndicesLoop() }), + "ForLoops.uIntArrayIndicesLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { uIntArrayIndicesLoop() }), + "ForLoops.uShortArrayIndicesLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { uShortArrayIndicesLoop() }), + "ForLoops.uLongArrayIndicesLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { uLongArrayIndicesLoop() }), "Inline.calculate" to BenchmarkEntryWithInit.create(::InlineBenchmark, { calculate() }), "Inline.calculateInline" to BenchmarkEntryWithInit.create(::InlineBenchmark, { calculateInline() }), "Inline.calculateGeneric" to BenchmarkEntryWithInit.create(::InlineBenchmark, { calculateGeneric() }), diff --git a/kotlin-native/performance/ring/src/main/kotlin/org/jetbrains/ring/ForLoopsBenchmark.kt b/kotlin-native/performance/ring/src/main/kotlin/org/jetbrains/ring/ForLoopsBenchmark.kt index 67dc5dc6533..d75e53b1ac8 100644 --- a/kotlin-native/performance/ring/src/main/kotlin/org/jetbrains/ring/ForLoopsBenchmark.kt +++ b/kotlin-native/performance/ring/src/main/kotlin/org/jetbrains/ring/ForLoopsBenchmark.kt @@ -20,6 +20,18 @@ class ForLoopsBenchmark { it.toFloat() } + private val uIntArray = UIntArray(BENCHMARK_SIZE) { + it.toUInt() + } + + private val uShortArray = UShortArray(BENCHMARK_SIZE) { + it.toUShort() + } + + private val uLongArray = ULongArray(BENCHMARK_SIZE) { + it.toULong() + } + fun arrayLoop(): Long { var sum = 0L for (e in array) { @@ -60,6 +72,30 @@ class ForLoopsBenchmark { return sum } + fun uIntArrayLoop(): ULong { + var sum: ULong = 0u + for (e in uIntArray) { + sum += e + } + return sum + } + + fun uShortArrayLoop(): ULong { + var sum: ULong = 0u + for (e in uShortArray) { + sum += e + } + return sum + } + + fun uLongArrayLoop(): ULong { + var sum: ULong = 0u + for (e in uLongArray) { + sum += e + } + return sum + } + // Iterations over .indices fun arrayIndicesLoop(): Long { @@ -101,4 +137,28 @@ class ForLoopsBenchmark { } return sum } + + fun uIntArrayIndicesLoop(): ULong { + var sum: ULong = 0u + for (i in uIntArray.indices) { + sum += uIntArray[i] + } + return sum + } + + fun uShortArrayIndicesLoop(): ULong { + var sum: ULong = 0u + for (i in uShortArray.indices) { + sum += uShortArray[i] + } + return sum + } + + fun uLongArrayIndicesLoop(): ULong { + var sum: ULong = 0u + for (i in uLongArray.indices) { + sum += uLongArray[i] + } + return sum + } } \ No newline at end of file