Android下Protobuff框架性能测试结果

发表于:2014-7-25 11:10

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:Captor    来源:51Testing软件测试网采编

  android 下Protobuff常用的框架有三个: protobuff自身,  square出的wire , protostuff
  由于protobuff会为每个属性生成大量不常用的方法,当程序比较复杂时容易超过android的60K个方法的上限, 所以本次测试未包括protobuff
  测试逻辑是循环100次序列化100个元素的数组,并反序列化,求平均值,代码如下:
  wire的测试代码:
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>();
ListItem.Builder itemBuilder = new ListItem.Builder();
ListItem item;
for (int j = 0; j < 100; j++) {
item = itemBuilder.title("test Title"+i+":"+j)
.remark("test Remark"+i+":"+j)
.coverUrl("http://pic.ozreader.com/abc.pic")
.uri("PKB:TESTURI")
.build();
itemList.add(item);
}
ScrollList.Builder listBuilder= new ScrollList.Builder();
ScrollList list = listBuilder.haveMore(false).tags(itemList).build();
byte[] dataBuffer = list.toByteArray();
serializeTime = System.currentTimeMillis()-startTime;
Wire wire = new Wire();
try {
ScrollList resultList = wire.parseFrom(dataBuffer, ScrollList.class);
if (resultList == null){
Log.e("TEST", "resultList is null");
break;
}else if (resultList.tags == null){
Log.e("TEST", "resultList.tags is null");
break;
}else if (resultList.tags.size() <= 0){
Log.e("TEST", "resultList.tags is empty");
break;
}else if (resultList.tags.size() != 100){
Log.e("TEST", "resultList.tags is wrong");
break;
}else if (!resultList.tags.get(0).uri.equals("PKB:TESTURI")){
Log.e("TEST", "resultList.tags content is wrong");
break;
}
deserializeTime = System.currentTimeMillis()-startTime-serializeTime;
} catch (IOException e) {
e.printStackTrace();
}
}
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+"\n");
if (isCancel){
text1.append("测试中断.");
btn.setText("开始测试");
}else if (runCount < 100){
new TestTask(text1,btn).execute();
}else{
isCancel = true;
text1.append("测试完成.");
btn.setText("开始测试");
}
}
}
21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号