Skip to content

Commit 88451ac

Browse files
authored
Merge branch 'Sloy:master' into master
2 parents a74b5b8 + 89ff9ec commit 88451ac

File tree

14 files changed

+1146
-956
lines changed

14 files changed

+1146
-956
lines changed

README.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
This project aims to measure the performance of several Dependency Injection frameworks (or Service Locators) in different devices.
44

55
## Libraries tested
6-
- [Koin](https://insert-koin.io/) - 2.0.0-alpha-3
7-
- [Kodein](http://kodein.org/Kodein-DI/) - 5.3.0
8-
- [Dagger 2](https://google.github.io/dagger/) - 2.16
9-
- [Katana](https://github.com/rewe-digital-incubator/katana/) - 1.2.2
6+
- [Koin](https://insert-koin.io/) - 2.0.1
7+
- [Kodein](http://kodein.org/Kodein-DI/) - 6.3.3
8+
- [Dagger 2](https://google.github.io/dagger/) - 2.24
9+
- [Katana](https://github.com/rewe-digital-incubator/katana/) - 1.7.1
1010

1111
## The test
1212
The test data are classes with dependencies in a structure similar to Fibonacci sequence, to simulate multiple levels of transitive dependencies.
@@ -28,9 +28,10 @@ Results can be quite different between different devices, so here are some resul
2828
- [OnePlus One](#oneplus-one)
2929
- [OnePlus 5](#oneplus-5)
3030
- [Nexus 6](#nexus-6)
31+
- [OnePlus 5T](#oneplus-5t) (dependencies updated)
3132

3233
### Samsung Galaxy J5
33-
samsung j5nlte with Android 6.0.1
34+
Samsung j5nlte with Android 6.0.1
3435

3536
Library | Setup Kotlin | Setup Java | Inject Kotlin | Inject Java
3637
--- | ---:| ---:| ---:| ---:
@@ -41,7 +42,7 @@ Library | Setup Kotlin | Setup Java | Inject Kotlin | Inject Java
4142
**Dagger** | 0.02 ms | 0.02 ms | 0.27 ms | 0.23 ms
4243

4344
### Samsung Galaxy S8
44-
samsung dreamlte with Android 8.0.0
45+
Samsung dreamlte with Android 8.0.0
4546

4647
Library | Setup Kotlin | Setup Java | Inject Kotlin | Inject Java
4748
--- | ---:| ---:| ---:| ---:
@@ -63,7 +64,7 @@ Library | Setup Kotlin | Setup Java | Inject Kotlin | Inject Java
6364
**Dagger** | 0.00 ms | 0.00 ms | 0.03 ms | 0.02 ms
6465

6566
### Xiaomi MI A1
66-
xiaomi tissot_sprout with Android 8.1.0
67+
Xiaomi tissot_sprout with Android 8.1.0
6768

6869
Library | Setup Kotlin | Setup Java | Inject Kotlin | Inject Java
6970
--- | ---:| ---:| ---:| ---:
@@ -74,7 +75,7 @@ Library | Setup Kotlin | Setup Java | Inject Kotlin | Inject Java
7475
**Dagger** | 0.02 ms | 0.02 ms | 0.28 ms | 0.21 ms
7576

7677
### OnePlus One
77-
oneplus A0001 with Android 5.0.2
78+
OnePlus A0001 with Android 5.0.2
7879

7980
Library | Setup Kotlin | Setup Java | Inject Kotlin | Inject Java
8081
--- | ---:| ---:| ---:| ---:
@@ -96,7 +97,7 @@ Library | Setup Kotlin | Setup Java | Inject Kotlin | Inject Java
9697
**Dagger** | 0.00 ms | 0.00 ms | 0.04 ms | 0.02 ms
9798

9899
### Nexus 6
99-
google shamu with Android 7.1.1
100+
Google shamu with Android 7.1.1
100101

101102
Library | Setup Kotlin | Setup Java | Inject Kotlin | Inject Java
102103
--- | ---:| ---:| ---:| ---:
@@ -105,3 +106,14 @@ Library | Setup Kotlin | Setup Java | Inject Kotlin | Inject Java
105106
**Katana** | 1.23 ms | 1.16 ms | 0.31 ms | 0.27 ms
106107
**Custom** | 0.29 ms | 0.29 ms | 0.20 ms | 0.31 ms
107108
**Dagger** | 0.03 ms | 0.03 ms | 0.22 ms | 0.15 ms
109+
110+
### OnePlus 5T
111+
OnePlus OnePlus5T with Android 9.0
112+
113+
Library | Setup Kotlin | Setup Java | Inject Kotlin | Inject Java
114+
--- | ---:| ---:| ---:| ---:
115+
**Koin** | 0.45 ms | 0.47 ms | 0.06 ms | 0.05 ms
116+
**Kodein** | 5.21 ms | 5.30 ms | 0.09 ms | 0.09 ms
117+
**Katana** | 0.34 ms | 0.37 ms | 0.04 ms | 0.04 ms
118+
**Custom** | 0.08 ms | 0.08 ms | 0.03 ms | 0.03 ms
119+
**Dagger** | 0.00 ms | 0.00 ms | 0.03 ms | 0.04 ms

app/build.gradle

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,38 @@ android {
1919
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2020
}
2121
}
22+
23+
// Fix for "Cannot inline bytecode built with JVM target 1.8 into bytecode
24+
// that is being built with JVM target 1.6"
25+
compileOptions {
26+
sourceCompatibility = 1.8
27+
targetCompatibility = 1.8
28+
}
29+
30+
kotlinOptions {
31+
jvmTarget = "1.8"
32+
}
2233
}
2334

2435
dependencies {
2536
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
26-
implementation 'androidx.appcompat:appcompat:1.0.2'
37+
implementation 'androidx.appcompat:appcompat:1.1.0'
2738
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
2839
implementation 'com.google.android.material:material:1.0.0'
40+
implementation "androidx.core:core-ktx:1.2.0-alpha04"
41+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.2"
42+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.2"
2943

3044
// Koin
31-
implementation "org.koin:koin-android:2.0.0-alpha-3"
45+
implementation "org.koin:koin-android:2.0.1"
3246

3347
// Kodein
34-
implementation 'org.kodein.di:kodein-di-erased-jvm:5.3.0'
48+
implementation 'org.kodein.di:kodein-di-erased-jvm:6.3.3'
3549

3650
// Dagger
37-
implementation 'com.google.dagger:dagger:2.16'
38-
kapt 'com.google.dagger:dagger-compiler:2.16'
51+
implementation 'com.google.dagger:dagger:2.24'
52+
kapt 'com.google.dagger:dagger-compiler:2.24'
3953

4054
// Katana
41-
implementation 'com.github.rewe-digital-incubator.katana:katana-android:1.2.2'
55+
implementation 'org.rewedigital.katana:katana-android:1.7.1'
4256
}

app/src/main/java/com/sloydev/dependencyinjectionperformance/InjectionTest.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import com.sloydev.dependencyinjectionperformance.dagger2.JavaDaggerComponent
1010
import com.sloydev.dependencyinjectionperformance.dagger2.KotlinDaggerComponent
1111
import com.sloydev.dependencyinjectionperformance.katana.katanaJavaModule
1212
import com.sloydev.dependencyinjectionperformance.katana.katanaKotlinModule
13+
import com.sloydev.dependencyinjectionperformance.kodein.kodeinKotlinModule
14+
import com.sloydev.dependencyinjectionperformance.kodein.kodeinJavaModule
1315
import com.sloydev.dependencyinjectionperformance.koin.koinJavaModule
1416
import com.sloydev.dependencyinjectionperformance.koin.koinKotlinModule
1517
import org.kodein.di.Kodein
@@ -23,7 +25,6 @@ import org.rewedigital.katana.Component
2325
import org.rewedigital.katana.Katana
2426
import org.rewedigital.katana.android.environment.AndroidEnvironmentContext
2527
import org.rewedigital.katana.android.environment.AndroidEnvironmentContext.Profile.SPEED
26-
import org.rewedigital.katana.createComponent
2728
import javax.inject.Inject
2829

2930
class InjectionTest : KoinComponent {
@@ -33,7 +34,7 @@ class InjectionTest : KoinComponent {
3334

3435
private val rounds = 100
3536

36-
fun runTests() {
37+
fun runTests(): List<LibraryResult> {
3738
val results = listOf(
3839
koinTest(),
3940
kodeinTest(),
@@ -42,6 +43,7 @@ class InjectionTest : KoinComponent {
4243
daggerTest()
4344
)
4445
reportMarkdown(results)
46+
return results
4547
}
4648

4749
private fun reportMarkdown(results: List<LibraryResult>) {
@@ -102,8 +104,8 @@ class InjectionTest : KoinComponent {
102104
test = { kodein.direct.instance<Fib8>() }
103105
),
104106
Variant.JAVA to runTest(
105-
setup = { kodein = Kodein { import(kodeinKotlinModule) } },
106-
test = { kodein.direct.instance<Fib8>() }
107+
setup = { kodein = Kodein { import(kodeinJavaModule) } },
108+
test = { kodein.direct.instance<FibonacciJava.Fib8>() }
107109
)
108110
))
109111
}
@@ -114,11 +116,11 @@ class InjectionTest : KoinComponent {
114116
lateinit var component: Component
115117
return LibraryResult("Katana", mapOf(
116118
Variant.KOTLIN to runTest(
117-
setup = { component = createComponent(modules = listOf(katanaKotlinModule)) },
119+
setup = { component = Component(modules = listOf(katanaKotlinModule)) },
118120
test = { component.injectNow<Fib8>() }
119121
),
120122
Variant.JAVA to runTest(
121-
setup = { component = createComponent(modules = listOf(katanaJavaModule)) },
123+
setup = { component = Component(modules = listOf(katanaJavaModule)) },
122124
test = { component.injectNow<FibonacciJava.Fib8>() }
123125
)
124126
))
Lines changed: 91 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
package com.sloydev.dependencyinjectionperformance
22

3+
import android.annotation.SuppressLint
4+
import android.graphics.Typeface
5+
import android.os.Build
36
import android.os.Bundle
7+
import android.view.View
8+
import android.view.ViewGroup
9+
import android.widget.TableRow
10+
import android.widget.TextView
411
import androidx.appcompat.app.AppCompatActivity
5-
import com.google.android.material.snackbar.Snackbar
12+
import androidx.core.view.GravityCompat
13+
import androidx.core.view.plusAssign
14+
import androidx.core.view.updatePadding
615
import kotlinx.android.synthetic.main.activity_main.*
16+
import kotlinx.android.synthetic.main.content_main.*
717

818
class MainActivity : AppCompatActivity() {
919

@@ -12,12 +22,88 @@ class MainActivity : AppCompatActivity() {
1222
setContentView(R.layout.activity_main)
1323
setSupportActionBar(toolbar)
1424

15-
fab.setOnClickListener { view ->
16-
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
17-
.setAction("Action", null).show()
25+
fab.setOnClickListener {
26+
runTests()
1827
}
1928

20-
InjectionTest().runTests()
29+
runTests()
30+
}
31+
32+
private fun runTests() {
33+
val results = InjectionTest().runTests()
34+
reportOnLogcat(results)
35+
reportOnScreen(results)
36+
}
37+
38+
private fun reportOnLogcat(results: List<LibraryResult>) {
39+
log("Done!\n")
40+
log("\n")
41+
log("${Build.BRAND} ${Build.DEVICE} with Android ${Build.VERSION.RELEASE}\n")
42+
log("\n")
43+
log("Library | Setup Kotlin | Setup Java | Inject Kotlin | Inject Java\n")
44+
log("--- | ---:| ---:| ---:| ---:\n")
45+
results.forEach {
46+
log("**${it.injectorName}** | ${it[Variant.KOTLIN].startupTime.median().format()} | ${it[Variant.JAVA].startupTime.median().format()} | ${it[Variant.KOTLIN].injectionTime.median().format()} | ${it[Variant.JAVA].injectionTime.median().format()}\n")
47+
}
48+
}
49+
50+
@SuppressLint("SetTextI18n")
51+
private fun reportOnScreen(results: List<LibraryResult>) {
52+
deviceInfo.text = """
53+
${Build.BRAND} · ${Build.DEVICE}
54+
Android ${Build.VERSION.RELEASE} (sdk ${Build.VERSION.SDK_INT})
55+
""".trimIndent()
56+
57+
results.forEach { result ->
58+
table += row(
59+
nameCell(result.injectorName),
60+
timeCell(result[Variant.JAVA].startupTime.median()),
61+
timeCell(result[Variant.KOTLIN].startupTime.median()),
62+
timeCell(result[Variant.JAVA].injectionTime.median()),
63+
timeCell(result[Variant.KOTLIN].injectionTime.median())
64+
)
65+
}
66+
67+
table.addView(
68+
separator(),
69+
ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1.dp)
70+
)
71+
}
72+
73+
private fun timeCell(time: Double): TextView {
74+
return TextView(this).apply {
75+
text = time.format()
76+
gravity = GravityCompat.END
77+
}
78+
}
79+
80+
private fun nameCell(name: String): TextView {
81+
return TextView(this).apply {
82+
text = name
83+
setTypeface(null, Typeface.BOLD)
84+
}
85+
}
86+
87+
private fun row(vararg cells: View): TableRow {
88+
return TableRow(this).also { row ->
89+
cells.forEach { cell ->
90+
row += cell
91+
}
92+
row.updatePadding(
93+
top = 4.dp,
94+
bottom = 4.dp
95+
)
96+
}
97+
}
98+
99+
private fun separator(): View {
100+
return View(this).apply {
101+
setBackgroundColor(resources.getColor(R.color.colorAccent))
102+
updatePadding(
103+
top = 4.dp,
104+
bottom = 4.dp
105+
)
106+
}
21107
}
22108

23109
}

app/src/main/java/com/sloydev/dependencyinjectionperformance/Utilities.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.sloydev.dependencyinjectionperformance
22

3+
import android.content.res.Resources
34
import android.util.Log
45
import java.util.*
56
import kotlin.system.measureNanoTime
@@ -28,4 +29,7 @@ fun List<Milliseconds>.median() = sorted().let { (it[it.size / 2] + it[(it.size
2829

2930
fun log(msg: String) {
3031
Log.i("DI-TEST", msg)
31-
}
32+
}
33+
34+
val Int.dp: Int
35+
get() = (this * Resources.getSystem().displayMetrics.density).toInt()

0 commit comments

Comments
 (0)