????protobuff????????:
public void onClickButton(View view){
if (TestTask.isCancel){
TestTask.isCancel = false;
TestTask.sumDeserializeTime = 0;
TestTask.sumTime = 0;
TestTask.runCount = 0;
TextView text1 = (TextView) findViewById(R.id.textView2);
text1.setText("");
new TestTask( (TextView) findViewById(R.id.textView2)
?? (TextView) findViewById(R.id.button1)).execute();
((TextView)view).setText("?????У?????ж?");
}else{
((TextView)view).setText("?????ж?...");
TestTask.isCancel = true;
}
}
static class TestTask extends AsyncTask<Void??Void??Long>{
long serializeTime=0;
long deserializeTime=0;
static long sumTime=0;
static long sumDeserializeTime=0;
static int runCount=0;
static boolean isCancel=true;
TextView text1;
TextView btn;
public TestTask(TextView text1??TextView btn) {
this.text1 = text1;
this.btn = btn;
}
@Override
protected Long doInBackground(Void... params) {
long startTime = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
List<ListItem> itemList = new ArrayList<ListItem>();
ScrollList list = new ScrollList();
list.setHaveMore(false);
list.setTagsList(itemList);
ListItem item;
for (int j = 0; j < 100; j++) {
item = new ListItem();
item.setTitle("test Title"+i+":"+j);
item.setRemark("test Remark"+i+":"+j);
item.setCoverUrl("http://pic.ozreader.com/abc.pic");
item.setUri("PKB:TESTURI");
itemList.add(item);
}
LinkedBuffer buffer = LinkedBuffer.allocate(1024);
byte[] dataBuffer = ProtobufIOUtil.toByteArray(list?? ScrollList.getSchema()?? buffer);
serializeTime = System.currentTimeMillis()-startTime;
ScrollList resultList = new ScrollList();
ProtobufIOUtil.mergeFrom(dataBuffer?? resultList?? ScrollList.getSchema());
if (resultList.getTagsList() == null){
Log.e("TEST"?? "resultList.tags is null");
break;
}else if (resultList.getTagsList().size() <= 0){
Log.e("TEST"?? "resultList.tags is empty");
break;
}else if (resultList.getTagsList().size() != 100){
Log.e("TEST"?? "resultList.tags is wrong");
break;
}else if (!resultList.getTagsList().get(0).getUri().equals("PKB:TESTURI")){
Log.e("TEST"?? "resultList.tags content is wrong");
break;
}
deserializeTime = System.currentTimeMillis()-startTime-serializeTime;
}
return System.currentTimeMillis() - startTime;
}
@Override
protected void onPostExecute(Long result) {
sumTime += result;
sumDeserializeTime += deserializeTime;
runCount ++;
text1.append("result:"+result+"?? serializeTime:"+serializeTime+"?? deserializeTime:"+deserializeTime+"?? runCount:"+runCount+"?? avg:"+sumTime/runCount+"?? avg deserializeTime:"+sumDeserializeTime/runCount+" ");
if (isCancel){
text1.append("?????ж?.");
btn.setText("???????");
}else if (runCount < 100){
new TestTask(text1??btn).execute();
}else{
isCancel = true;
text1.append("???????.");
btn.setText("???????");
}
}
}
???????????(??λ????):
???????????:????MX2
????1) wire 1.5.1 ????? https://github.com/square/wire
????avg: 1860~1907 ?? С???1500????????????? ???????????
????avg deserializeTime: 9~10?? С???5?????????????????????
????2) protostuff 1.0.8 ????? https://code.google.com/p/protostuff/
????avg: 1100~1150???????? ?? С???450???????????????????????????10?κ??????11XX????????600~800??????????????????????????£???????GC???????й??????? ???????????仯?????.
????avg deserializeTime: 6?? С???3????????????????????????????????5????д?16?????.
????????: wire??????????????protostuff?? ??????????????????.  ?????protostuff??????????????pojo???????????????protobuff??wire??builder????????鷳. ??????????????????????????app?????protostuff .