File tree Expand file tree Collapse file tree 8 files changed +45
-15
lines changed
java/com/sloydev/dependencyinjectionperformance Expand file tree Collapse file tree 8 files changed +45
-15
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,9 @@ dependencies {
26
26
implementation ' androidx.appcompat:appcompat:1.0.2'
27
27
implementation ' androidx.constraintlayout:constraintlayout:1.1.3'
28
28
implementation ' com.google.android.material:material:1.0.0'
29
+ implementation " androidx.core:core-ktx:1.2.0-alpha01"
30
+ implementation " org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1"
31
+ implementation " org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.1"
29
32
30
33
// Koin
31
34
implementation " org.koin:koin-android:2.0.0-alpha-3"
Original file line number Diff line number Diff line change @@ -28,12 +28,14 @@ import javax.inject.Inject
28
28
29
29
class InjectionTest : KoinComponent {
30
30
31
+ private lateinit var callback: (String ) -> Unit
31
32
private val kotlinDaggerTest = KotlinDaggerTest ()
32
33
private val javaDaggerTest = JavaDaggerTest ()
33
34
34
35
private val rounds = 100
35
36
36
- fun runTests () {
37
+ fun runTests (callback : (String ) -> Unit ) {
38
+ this .callback = callback
37
39
val results = listOf (
38
40
koinTest(),
39
41
kodeinTest(),
@@ -45,15 +47,19 @@ class InjectionTest : KoinComponent {
45
47
}
46
48
47
49
private fun reportMarkdown (results : List <LibraryResult >) {
48
- log(" Done!" )
49
- log(" " )
50
- log(" ${Build .BRAND } ${Build .DEVICE } with Android ${Build .VERSION .RELEASE } " )
51
- log(" " )
52
- log(" Library | Setup Kotlin | Setup Java | Inject Kotlin | Inject Java" )
53
- log(" --- | ---:| ---:| ---:| ---:" )
50
+ val sb = StringBuilder ()
51
+ log(" Done!\n " )
52
+ sb.append(" \n " )
53
+ sb.append(" ${Build .BRAND } ${Build .DEVICE } with Android ${Build .VERSION .RELEASE } \n " )
54
+ sb.append(" \n " )
55
+ sb.append(" Library | Setup Kotlin | Setup Java | Inject Kotlin | Inject Java\n " )
56
+ sb.append(" --- | ---:| ---:| ---:| ---:\n " )
54
57
results.forEach {
55
- 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()} " )
58
+ sb.append (" **${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 " )
56
59
}
60
+
61
+ log(sb.toString())
62
+ this .callback.invoke(sb.toString())
57
63
}
58
64
59
65
private fun runTest (
Original file line number Diff line number Diff line change @@ -4,20 +4,38 @@ import android.os.Bundle
4
4
import androidx.appcompat.app.AppCompatActivity
5
5
import com.google.android.material.snackbar.Snackbar
6
6
import kotlinx.android.synthetic.main.activity_main.*
7
+ import kotlinx.android.synthetic.main.content_main.*
8
+ import kotlinx.coroutines.Deferred
9
+ import kotlinx.coroutines.GlobalScope
10
+ import kotlinx.coroutines.async
7
11
8
12
class MainActivity : AppCompatActivity () {
9
13
14
+ private lateinit var job: Deferred <Unit >
15
+
10
16
override fun onCreate (savedInstanceState : Bundle ? ) {
11
17
super .onCreate(savedInstanceState)
12
18
setContentView(R .layout.activity_main)
13
19
setSupportActionBar(toolbar)
14
20
15
21
fab.setOnClickListener { view ->
16
- Snackbar .make(view, " Replace with your own action" , Snackbar .LENGTH_LONG )
17
- .setAction(" Action" , null ).show()
22
+ runTests()
18
23
}
19
24
20
- InjectionTest ().runTests()
25
+ runTests()
26
+ }
27
+
28
+ private fun runTests () {
29
+ runOnUiThread {
30
+ textView.text = getString(R .string.running_tests)
31
+ }
32
+ this .job = GlobalScope .async {
33
+ InjectionTest ().runTests {
34
+ runOnUiThread {
35
+ textView.text = it
36
+ }
37
+ }
38
+ }
21
39
}
22
40
23
41
}
Original file line number Diff line number Diff line change 29
29
android : layout_height =" wrap_content"
30
30
android : layout_gravity =" bottom|end"
31
31
android : layout_margin =" @dimen/fab_margin"
32
- app : srcCompat =" @android:drawable/ic_dialog_email " />
32
+ app : srcCompat =" @android:drawable/ic_media_play " />
33
33
34
34
</androidx .coordinatorlayout.widget.CoordinatorLayout>
Original file line number Diff line number Diff line change 10
10
tools : context =" .MainActivity" >
11
11
12
12
<TextView
13
+ android : id =" @+id/textView"
13
14
android : layout_width =" wrap_content"
14
15
android : layout_height =" wrap_content"
15
16
android : text =" Hello World!"
Original file line number Diff line number Diff line change 1
1
<resources >
2
2
<string name =" app_name" >Dependency Injection Performance</string >
3
3
<string name =" action_settings" >Settings</string >
4
+ <string name =" running_tests" >Running tests...</string >
4
5
</resources >
Original file line number Diff line number Diff line change 1
1
buildscript {
2
- ext. kotlin_version = ' 1.3.11 '
2
+ ext. kotlin_version = ' 1.3.31 '
3
3
repositories {
4
4
google()
5
5
jcenter()
6
6
}
7
7
dependencies {
8
- classpath ' com.android.tools.build:gradle:3.2 .1'
8
+ classpath ' com.android.tools.build:gradle:3.4 .1'
9
9
classpath " org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version "
10
10
}
11
11
}
Original file line number Diff line number Diff line change
1
+ # Thu May 02 15:26:21 MDT 2019
1
2
distributionBase =GRADLE_USER_HOME
2
3
distributionPath =wrapper/dists
3
- distributionUrl =https\://services.gradle.org/distributions/gradle-4.6-all.zip
4
4
zipStoreBase =GRADLE_USER_HOME
5
5
zipStorePath =wrapper/dists
6
+ distributionUrl =https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
You can’t perform that action at this time.
0 commit comments