[K/N] Added a benchmark on string array loop
This commit is contained in:
@@ -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() }),
|
||||
|
||||
+12
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user