[K/N][perf] Added benchmarks for unsigned arrays for-loops
This commit is contained in:
@@ -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() }),
|
||||
|
||||
+60
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user