Added benchmark for chain of elvises

This commit is contained in:
Elena Lepilkina
2020-05-28 10:52:15 +04:00
committed by LepilkinaElena
parent ebc7449f5f
commit edf13fdfa9
2 changed files with 14 additions and 0 deletions
+1
View File
@@ -77,6 +77,7 @@ class RingLauncher : Launcher() {
"DefaultArgument.testOneOfEight" to BenchmarkEntryWithInit.create(::DefaultArgumentBenchmark, { testOneOfEight() }),
"DefaultArgument.testEightOfEight" to BenchmarkEntryWithInit.create(::DefaultArgumentBenchmark, { testEightOfEight() }),
"Elvis.testElvis" to BenchmarkEntryWithInit.create(::ElvisBenchmark, { testElvis() }),
"Elvis.testCompositeElvis" to BenchmarkEntryWithInit.create(::ElvisBenchmark, { testCompositeElvis() }),
"Euler.problem1bySequence" to BenchmarkEntryWithInit.create(::EulerBenchmark, { problem1bySequence() }),
"Euler.problem1" to BenchmarkEntryWithInit.create(::EulerBenchmark, { problem1() }),
"Euler.problem2" to BenchmarkEntryWithInit.create(::EulerBenchmark, { problem2() }),
@@ -37,4 +37,17 @@ open class ElvisBenchmark {
Blackhole.consume(obj?.value ?: 0)
}
}
class Composite(val x : Int, val y : Composite?)
fun check(a : Composite?) : Int {
return a?.y?.x ?: (a?.x ?: 3)
}
fun testCompositeElvis(): Int {
var result = 0
for (i in 0..BENCHMARK_SIZE)
result += check(Composite(Random.nextInt(), Composite(Random.nextInt(), null)))
return result
}
}