Added benchmark for chain of elvises
This commit is contained in:
committed by
LepilkinaElena
parent
ebc7449f5f
commit
edf13fdfa9
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user