-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e140b3
commit c801702
Showing
6 changed files
with
114 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
benchmark/src/androidTest/java/com/haroldadmin/vector/benchmark/actorStateStore/Benchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...k/src/androidTest/java/com/haroldadmin/vector/benchmark/reflection/NewInstanceCreation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.haroldadmin.vector.benchmark.reflection | ||
|
||
import androidx.benchmark.junit4.BenchmarkRule | ||
import androidx.benchmark.junit4.measureRepeated | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import org.junit.Ignore | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import kotlin.reflect.full.createInstance | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@Ignore("Don't run benchmarks with regular builds") | ||
internal class NewInstanceCreation { | ||
|
||
@get:Rule val benchmarkRule = BenchmarkRule() | ||
|
||
@Test | ||
fun kotlinReflectionNewInstanceCreation() = benchmarkRule.measureRepeated { | ||
val instance = ImplementingClass::class.createInstance() | ||
} | ||
|
||
@Test | ||
fun javaReflectionNewInstanceCreation() = benchmarkRule.measureRepeated { | ||
val instance = ImplementingClass::class.java.newInstance() | ||
} | ||
|
||
// Java Reflection version is 6x-7x faster than the kotlin version | ||
} |
40 changes: 40 additions & 0 deletions
40
.../androidTest/java/com/haroldadmin/vector/benchmark/reflection/SuperClassCheckBenchMark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.haroldadmin.vector.benchmark.reflection | ||
|
||
import androidx.benchmark.junit4.BenchmarkRule | ||
import androidx.benchmark.junit4.measureRepeated | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import kotlin.reflect.full.isSuperclassOf | ||
|
||
internal interface SuperTypeInterface | ||
internal class ImplementingClass : SuperTypeInterface | ||
|
||
// @Ignore("Don't run benchmarks for regular builds") | ||
@RunWith(AndroidJUnit4::class) | ||
internal class SuperClassCheckBenchMark { | ||
|
||
@get:Rule | ||
val benchmarkRule = BenchmarkRule() | ||
|
||
@Test | ||
fun kotlinReflectionSuperClassCheck() { | ||
benchmarkRule.measureRepeated { | ||
val superClass = SuperTypeInterface::class | ||
val subClass = ImplementingClass::class | ||
superClass.isSuperclassOf(subClass) | ||
} | ||
} | ||
|
||
@Test | ||
fun javaReflectionSuperClassCheck() { | ||
benchmarkRule.measureRepeated { | ||
val superClass = SuperTypeInterface::class.java | ||
val subClass = ImplementingClass::class.java | ||
superClass.isAssignableFrom(subClass) | ||
} | ||
} | ||
|
||
// Result is that Kotlin Reflection is around 150x-200x slower than Java Reflection for this particular check | ||
} |
38 changes: 38 additions & 0 deletions
38
...src/androidTest/java/com/haroldadmin/vector/benchmark/reflection/UnderlyingClassAccess.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.haroldadmin.vector.benchmark.reflection | ||
|
||
import androidx.benchmark.junit4.BenchmarkRule | ||
import androidx.benchmark.junit4.measureRepeated | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
// @Ignore("Don't run benchmarks with regular builds") | ||
@RunWith(AndroidJUnit4::class) | ||
class UnderlyingClassAccess { | ||
|
||
@get:Rule val benchmarkRule = BenchmarkRule() | ||
|
||
@Test | ||
fun kotlinClassAccess() { | ||
benchmarkRule.measureRepeated { | ||
val klass = ImplementingClass::class | ||
} | ||
} | ||
|
||
@Test | ||
fun javaClassAccess() { | ||
benchmarkRule.measureRepeated { | ||
val clazz = ImplementingClass::class.java | ||
} | ||
} | ||
|
||
@Test | ||
fun javaClassToKotlin() { | ||
benchmarkRule.measureRepeated { | ||
val klass = ImplementingClass::class.java.kotlin | ||
} | ||
} | ||
|
||
// Accessing the underlying java class or kotlin class is equivalent in performance | ||
} |
4 changes: 2 additions & 2 deletions
4
...ndroidTest/java/com/haroldadmin/vector/benchmark/regularStateStore/StateStoreBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters