Android under Protobuff Framework performance test results

Source: Internet
Author: User

There are three commonly used frameworks for Android under Protobuff: Protobuff itself, square-out wire, Protostuff

Since Protobuff generates a large number of infrequently used methods for each attribute, it is easier to exceed the upper limit of 60K methods for Android when the program is more complex, so this test does not include Protobuff

The test logic is to loop 100 times to serialize an array of 100 elements, and deserialize, averaging, the code is as follows:

Test code for Wire:

 Public voidOnClickButton (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 (""); NewTesttask ((TextView) Findviewbyid (R.ID.TEXTVIEW2), (TextView) Findviewbyid (R.id.button1)). Execute            (); ((TextView) view). SetText ("In the test, click Break"); }Else{(TextView) view). SetText ("Interrupting ..."); Testtask.iscancel=true; }    }        Static classTesttaskextendsAsynctask<void,void,long>{        LongSerializetime=0; LongDeserializetime=0; Static LongSumtime=0; Static LongSumdeserializetime=0; Static intRuncount=0; Static BooleanIscancel=true;        TextView Text1;        TextView btn;  Publictesttask (TextView text1,textview btn) { This. Text1 =Text1;  This. btn =btn; } @OverrideprotectedLong doinbackground (Void ... params) {LongStartTime =System.currenttimemillis ();  for(inti = 0; I < 100; i++) {List<ListItem> itemList =NewArraylist<listitem>(); Listitem.builder Itembuilder=NewListitem.builder ();                ListItem item;  for(intj = 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=NewScrolllist.builder (); Scrolllist List= Listbuilder.havemore (false). tags (itemList). build (); byte[] DataBuffer =List.tobytearray (); Serializetime= System.currenttimemillis ()-StartTime; Wire Wire=NewWire (); 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 (); }            }            returnSystem.currenttimemillis ()-StartTime; } @Overrideprotected voidOnPostExecute (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 ("Test interrupted."); Btn.settext ("Start Test"); }Else if(Runcount < 100){                NewTesttask (TEXT1,BTN). Execute (); }Else{Iscancel=true; Text1.append ("The test is complete."); Btn.settext ("Start Test"); }        }            }

Test code for Protobuff:

    publicvoid  OnClickButton (view view) {                if  (testtask.iscancel) {             false ;
Testtask.sumdeserializetime = 0;
       Testtask.sumtime = 0;
       Testtask.runcount = 0;
= (TextView) Findviewbyid (R.ID.TEXTVIEW2);
Text1.settext (""); NewTesttask ((TextView) Findviewbyid (R.ID.TEXTVIEW2), (TextView) Findviewbyid (R.id.button1)). Execute            (); ((TextView) view). SetText ("In the test, click Break"); }Else{(TextView) view). SetText ("Interrupting ..."); Testtask.iscancel=true; }    }        Static classTesttaskextendsAsynctask<void,void,long>{        LongSerializetime=0; LongDeserializetime=0; Static LongSumtime=0; Static LongSumdeserializetime=0; Static intRuncount=0; Static BooleanIscancel=true;        TextView Text1;        TextView btn;  Publictesttask (TextView text1,textview btn) { This. Text1 =Text1;  This. btn =btn; } @OverrideprotectedLong doinbackground (Void ... params) {LongStartTime =System.currenttimemillis ();  for(inti = 0; I < 100; i++) {List<ListItem> itemList =NewArraylist<listitem>(); Scrolllist List=Newscrolllist (); List.sethavemore (false);                                List.settagslist (itemList);                ListItem item;  for(intj = 0; J < 100; J + +) {Item=NewListItem (); 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=Newscrolllist ();                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; }            returnSystem.currenttimemillis ()-StartTime; } @Overrideprotected voidOnPostExecute (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 ("Test interrupted."); Btn.settext ("Start Test"); }Else if(Runcount < 100){                NewTesttask (TEXT1,BTN). Execute (); }Else{Iscancel=true; Text1.append ("The test is complete."); Btn.settext ("Start Test"); }        }    }

The test result is (in seconds):

Mobile Environment: Meizu MX2

1) wire 1.5.1 , url Https://github.com/square/wire

avg:1860~1907 , the minimum value is about 1500, rarely appear, the whole process of random distribution

avg deserializetime:9~10with a minimum value of approximately 5, rarely appearing, and the whole process randomly distributed

2) protostuff 1.0.8 , url https://code.google.com/p/protostuff/

avg:1100~1150, very stable, the minimum value of about 450, mainly concentrated in the previous cycles, 10 times after the cycle of stability in the 11XX, occasionally 600~800, repeated testing is basically the same, observe the automatic GC and no memory leak problem, Temporarily unsure of the cause of the change in speed.

avg deserializetime:6, the minimum value is about 3, rarely appear, mainly concentrated in the beginning, the overwhelming majority of 5, occasionally up to 16 of the situation.

Analysis: The performance of wire is obviously less than protostuff, the speed is not too stable, the ups and downs are larger. Considering the development mode of Protostuff is common Pojo way, more convenient, unlike Protobuff and wire builder way, Super trouble. So the final recommendation is not the logic of ultra-complex enterprise app all use Protostuff.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.