[K/N] Added a benchmark on string array loop

This commit is contained in:
Igor Chevdar
2023-11-08 12:18:25 +02:00
committed by Space Team
parent 27a4cb6c12
commit 6c691b497a
2 changed files with 13 additions and 0 deletions
@@ -142,6 +142,7 @@ 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.stringArrayLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { stringArrayLoop() }),
"ForLoops.uIntArrayLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { uIntArrayLoop() }),
"ForLoops.uShortArrayLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { uShortArrayLoop() }),
"ForLoops.uLongArrayLoop" to BenchmarkEntryWithInit.create(::ForLoopsBenchmark, { uLongArrayLoop() }),
@@ -16,6 +16,10 @@ class ForLoopsBenchmark {
private val string: String = charArray.joinToString()
private val stringArray: Array<String> = Array(BENCHMARK_SIZE) {
it.toString()
}
private val floatArray: FloatArray = FloatArray(BENCHMARK_SIZE) {
it.toFloat()
}
@@ -64,6 +68,14 @@ class ForLoopsBenchmark {
return sum
}
fun stringArrayLoop(): Long {
var sum = 0L
for (e in stringArray) {
sum += e.length.toLong()
}
return sum
}
fun floatArrayLoop(): Double {
var sum = 0.0
for (e in floatArray) {