Skip to content

Commit c80b6a1

Browse files
committed
see 07/15 log
1 parent 2511945 commit c80b6a1

File tree

28 files changed

+743
-66
lines changed

28 files changed

+743
-66
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
* `19/07/10` [upd] Bus plugin for use BusUtils. Publish bus plugin v2.0.
2+
* `19/07/10` [add] Api plugin for use ApiUtils. Publish api plugin v1.0.
3+
* `19/07/09` [upd] The frame of project.
4+
* `19/07/06` [upd] BusUtils which behave same as EventBus.
5+
* `19/07/03` [add] ApiUtils which decoupling modules.
16
* `19/06/30` [add] LanguageUtils support activity's class name. Publish v1.24.7.
27
* `19/06/29` [add] ClickUtils#OnMultiClickListener, and remove dangerous function. Publish v1.24.6.
38
* `19/06/28` [add] LanguageUtils. Publish v1.24.5.

art/frame.png

-56.2 KB
Binary file not shown.

buildSrc/src/main/groovy/Config.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class Config {
9999
glide : new DepConfig("com.github.bumptech.glide:glide:4.7.1"),
100100
retrofit : new DepConfig("com.squareup.retrofit2:retrofit:2.4.0"),
101101
commons_io : new DepConfig("commons-io:commons-io:2.6"),
102+
eventbus : new DepConfig("org.greenrobot:eventbus:3.1.1"),
102103

103104
test : [
104105
junit : new DepConfig("junit:junit:4.12"),

buildSrc/src/main/groovy/ConfigUtils.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,14 @@ class ConfigUtils {
164164
}
165165
})
166166
StringBuilder sb = new StringBuilder()
167-
taskInfoList.each {
168-
sb.append(String.format("%7sms %s\n", it.exeDuration, it.task.path))
169-
}
170167
int buildSec = (System.currentTimeMillis() - startBuildMillis) / 1000;
171168
int m = buildSec / 60;
172169
int s = buildSec % 60;
173-
def timeInfo = (m == 0 ? "${s}s" : "${m}m ${s}s")
170+
def timeInfo = (m == 0 ? "${s}s" : "${m}m ${s}s (${buildSec}s)")
174171
sb.append("BUILD FINISHED in $timeInfo")
172+
taskInfoList.each {
173+
sb.append(String.format("%7sms %s\n", it.exeDuration, it.task.path))
174+
}
175175
def content = sb.toString()
176176
GLog.l(content)
177177
File file = new File(result.gradle.rootProject.buildDir.getAbsolutePath(),

feature/launcher/app/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apply plugin: 'kotlin-kapt'
2+
3+
dependencies {
4+
kapt 'org.greenrobot:eventbus-annotation-processor:3.0.1'
5+
}

feature/utilcode/pkg/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@
8989
android:name=".feature.bus.BusActivity"
9090
android:configChanges="orientation|keyboardHidden|screenSize"
9191
android:launchMode="singleTop" />
92+
<activity
93+
android:name=".feature.bus.BusCompareActivity"
94+
android:configChanges="orientation|keyboardHidden|screenSize"
95+
android:launchMode="singleTop" />
9296
<activity
9397
android:name=".feature.clean.CleanActivity"
9498
android:configChanges="orientation|keyboardHidden|screenSize"

feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/bus/BusActivity.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class BusActivity : CommonTitleActivity() {
6666
busPost,
6767
busPostSticky,
6868
busPost2IoThread,
69-
busRemoveSticky
69+
busRemoveSticky,
70+
busStartCompare
7071
)
7172
}
7273

@@ -99,6 +100,9 @@ class BusActivity : CommonTitleActivity() {
99100
R.id.busRemoveSticky -> {
100101
BusUtils.removeSticky(TAG_STICKY_BUS)
101102
}
103+
R.id.busStartCompare -> {
104+
BusCompareActivity.start(this)
105+
}
102106
}
103107
}
104108

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
package com.blankj.utilcode.pkg.feature.bus
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import android.os.Bundle
6+
import android.view.View
7+
import com.blankj.lib.common.CommonTaskActivity
8+
import com.blankj.utilcode.pkg.R
9+
import com.blankj.utilcode.util.BusUtils
10+
import com.blankj.utilcode.util.ThreadUtils
11+
import kotlinx.android.synthetic.main.activity_busutils_vs_eventbus.*
12+
import org.greenrobot.eventbus.EventBus
13+
import java.util.*
14+
15+
16+
/**
17+
* ```
18+
* author: Blankj
19+
* blog : http://blankj.com
20+
* time : 2019/07/14
21+
* desc : demo about BusUtils
22+
* ```
23+
*/
24+
class BusCompareActivity : CommonTaskActivity<Unit>() {
25+
26+
override fun doInBackground() {
27+
28+
}
29+
30+
override fun runOnUiThread(data: Unit?) {
31+
32+
}
33+
34+
companion object {
35+
fun start(context: Context) {
36+
val starter = Intent(context, BusCompareActivity::class.java)
37+
context.startActivity(starter)
38+
}
39+
}
40+
41+
override fun bindTitle(): CharSequence {
42+
return getString(R.string.demo_bus)
43+
}
44+
45+
override fun initData(bundle: Bundle?) {}
46+
47+
override fun bindLayout(): Int {
48+
return R.layout.activity_busutils_vs_eventbus
49+
}
50+
51+
override fun initView(savedInstanceState: Bundle?, contentView: View?) {
52+
applyDebouncingClickListener(
53+
busCompareRegister10000TimesBtn,
54+
busComparePostTo1Subscriber1000000TimesBtn,
55+
busComparePostTo100Subscribers100000TimesBtn,
56+
busCompareUnregister10000TimesBtn
57+
)
58+
}
59+
60+
override fun doBusiness() {
61+
62+
}
63+
64+
override fun onDebouncingClick(view: View) {
65+
when (view.id) {
66+
R.id.busCompareRegister10000TimesBtn -> {
67+
compareRegister10000Times()
68+
}
69+
R.id.busComparePostTo1Subscriber1000000TimesBtn -> {
70+
comparePostTo1Subscriber1000000Times()
71+
}
72+
R.id.busComparePostTo100Subscribers100000TimesBtn -> {
73+
comparePostTo100Subscribers100000Times()
74+
}
75+
R.id.busCompareUnregister10000TimesBtn -> {
76+
compareUnregister10000Times()
77+
}
78+
}
79+
}
80+
81+
override fun onDestroy() {
82+
super.onDestroy()
83+
ThreadUtils.cancel(ThreadUtils.getCpuPool())
84+
}
85+
86+
/**
87+
* 注册 10000 个订阅者,共执行 10 次取平均值
88+
*/
89+
private fun compareRegister10000Times() {
90+
val eventBusTests = java.util.ArrayList<BusEvent>()
91+
val busUtilsTests = java.util.ArrayList<BusEvent>()
92+
93+
compareWithEventBus("Register 10000 times.", 10, 10000, object : CompareCallback {
94+
override fun runEventBus() {
95+
val test = BusEvent()
96+
EventBus.getDefault().register(test)
97+
eventBusTests.add(test)
98+
}
99+
100+
override fun runBusUtils() {
101+
val test = BusEvent()
102+
BusUtils.register(test)
103+
busUtilsTests.add(test)
104+
}
105+
106+
override fun restState() {
107+
for (test in eventBusTests) {
108+
EventBus.getDefault().unregister(test)
109+
}
110+
eventBusTests.clear()
111+
112+
for (test in busUtilsTests) {
113+
BusUtils.unregister(test)
114+
}
115+
busUtilsTests.clear()
116+
}
117+
}, object : OnFinishCallback {
118+
override fun onFinish() {
119+
120+
}
121+
})
122+
}
123+
124+
/**
125+
* 向 1 个订阅者发送 * 1000000 次,共执行 10 次取平均值
126+
*/
127+
private fun comparePostTo1Subscriber1000000Times() {
128+
comparePostTemplate("Post to 1 subscriber 1000000 times.", 1, 1000000)
129+
}
130+
131+
/**
132+
* 向 100 个订阅者发送 * 100000 次,共执行 10 次取平均值
133+
*/
134+
private fun comparePostTo100Subscribers100000Times() {
135+
comparePostTemplate("Post to 100 subscribers 100000 times.", 100, 100000)
136+
}
137+
138+
private fun comparePostTemplate(name: String, subscribeNum: Int, postTimes: Int) {
139+
val tests = java.util.ArrayList<BusEvent>()
140+
for (i in 0 until subscribeNum) {
141+
val test = BusEvent()
142+
EventBus.getDefault().register(test)
143+
BusUtils.register(test)
144+
tests.add(test)
145+
}
146+
147+
compareWithEventBus(name, 10, postTimes, object : CompareCallback {
148+
override fun runEventBus() {
149+
EventBus.getDefault().post("EventBus")
150+
}
151+
152+
override fun runBusUtils() {
153+
BusUtils.post("busUtilsFun", "BusUtils")
154+
}
155+
156+
override fun restState() {
157+
158+
}
159+
}, object : OnFinishCallback {
160+
override fun onFinish() {
161+
for (test in tests) {
162+
EventBus.getDefault().unregister(test)
163+
BusUtils.unregister(test)
164+
}
165+
}
166+
})
167+
}
168+
169+
/**
170+
* 注销 10000 个订阅者,共执行 10 次取平均值
171+
*/
172+
private fun compareUnregister10000Times() {
173+
val tests = ArrayList<BusEvent>()
174+
for (i in 0..9999) {
175+
val test = BusEvent()
176+
EventBus.getDefault().register(test)
177+
BusUtils.register(test)
178+
tests.add(test)
179+
}
180+
181+
compareWithEventBus("Unregister 10000 times.", 10, 1, object : CompareCallback {
182+
override fun runEventBus() {
183+
for (test in tests) {
184+
EventBus.getDefault().unregister(test)
185+
}
186+
}
187+
188+
override fun runBusUtils() {
189+
for (test in tests) {
190+
BusUtils.unregister(test)
191+
}
192+
}
193+
194+
override fun restState() {
195+
for (test in tests) {
196+
EventBus.getDefault().register(test)
197+
BusUtils.register(test)
198+
}
199+
}
200+
}, object : OnFinishCallback {
201+
override fun onFinish() {
202+
for (test in tests) {
203+
EventBus.getDefault().unregister(test)
204+
BusUtils.unregister(test)
205+
}
206+
}
207+
})
208+
}
209+
210+
/**
211+
* @param name 传入的测试函数名
212+
* @param sampleSize 样本数
213+
* @param times 每次执行的次数
214+
* @param callback 比较的回调函数
215+
* @param onFinishCallback 执行结束的回调
216+
*/
217+
private fun compareWithEventBus(name: String, sampleSize: Int, times: Int,
218+
callback: CompareCallback, onFinishCallback: OnFinishCallback) {
219+
setLoadingVisibility(true)
220+
setBtnEnabled(false)
221+
ThreadUtils.executeByCpu(object : ThreadUtils.Task<String>() {
222+
override fun doInBackground(): String {
223+
val dur = Array(2) { LongArray(sampleSize) }
224+
for (i in 0 until sampleSize) {
225+
var cur = System.currentTimeMillis()
226+
for (j in 0 until times) {
227+
callback.runEventBus()
228+
}
229+
dur[0][i] = System.currentTimeMillis() - cur
230+
cur = System.currentTimeMillis()
231+
for (j in 0 until times) {
232+
callback.runBusUtils()
233+
}
234+
dur[1][i] = System.currentTimeMillis() - cur
235+
callback.restState()
236+
}
237+
var eventBusAverageTime: Long = 0
238+
var busUtilsAverageTime: Long = 0
239+
for (i in 0 until sampleSize) {
240+
eventBusAverageTime += dur[0][i]
241+
busUtilsAverageTime += dur[1][i]
242+
}
243+
return name +
244+
"\nEventBusCostTime: " + eventBusAverageTime / sampleSize +
245+
"\nBusUtilsCostTime: " + busUtilsAverageTime / sampleSize;
246+
}
247+
248+
override fun onSuccess(result: String?) {
249+
onFinishCallback.onFinish()
250+
setBtnEnabled(true)
251+
setLoadingVisibility(false)
252+
this@BusCompareActivity.busCompareAboutTv.text = result
253+
}
254+
255+
override fun onCancel() {
256+
onFinishCallback.onFinish()
257+
setLoadingVisibility(false)
258+
setBtnEnabled(true)
259+
}
260+
261+
override fun onFail(t: Throwable?) {
262+
onFinishCallback.onFinish()
263+
setLoadingVisibility(false)
264+
setBtnEnabled(true)
265+
}
266+
})
267+
}
268+
269+
private fun setBtnEnabled(enable: Boolean) {
270+
busCompareRegister10000TimesBtn.isEnabled = enable
271+
busComparePostTo1Subscriber1000000TimesBtn.isEnabled = enable
272+
busCompareUnregister10000TimesBtn.isEnabled = enable
273+
}
274+
275+
interface CompareCallback {
276+
fun runEventBus()
277+
278+
fun runBusUtils()
279+
280+
fun restState()
281+
}
282+
283+
interface OnFinishCallback {
284+
fun onFinish()
285+
}
286+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.blankj.utilcode.pkg.feature.bus
2+
3+
import com.blankj.utilcode.util.BusUtils
4+
import org.greenrobot.eventbus.Subscribe
5+
6+
/**
7+
* ```
8+
* author: Blankj
9+
* blog : http://blankj.com
10+
* time : 2019/07/14
11+
* desc : demo about BusUtils
12+
* ```
13+
*/
14+
class BusEvent {
15+
@Subscribe
16+
fun eventBusFun(param: String) {
17+
}
18+
19+
@BusUtils.Bus(tag = "busUtilsFun")
20+
fun busUtilsFun(param: String) {
21+
}
22+
}

feature/utilcode/pkg/src/main/res/layout/activity_bus.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,12 @@
5454
android:layout_height="wrap_content"
5555
android:text="@string/bus_remove_sticky" />
5656

57+
<Button
58+
android:id="@+id/busStartCompare"
59+
style="@style/WideBtnStyle"
60+
android:layout_width="match_parent"
61+
android:layout_height="wrap_content"
62+
android:text="@string/bus_start_compare" />
63+
5764

5865
</LinearLayout>

0 commit comments

Comments
 (0)