The purpose of this paper is to compare the advantages and disadvantages of these four methods and to give a solution.
1. Test Environment Description CPU:I3-2310m CPU @ 2.10GHzVersion of the Os:linux (64-bit) Library: lua5.1, luajit2.0, note: 1. The Sproto library author uses the lua5.2 new Library bitwise Operators in the code, and does not match the lua5.1 environment we use, so we can replace lua5.2 with lua5.1 and Bit.numberlua. Operators.
2. Also tried to use the Protoc-gen-lua, but the solution of the table needs to be manually parsed, and time-consuming. 2. Test 2.0 test Function Interface Description
Library |
Function interface |
Input/output parameter |
Note |
Sproto |
1.en=cookie.encode (AB) 2.de=cookie.decode (en) |
1. Input:ab is table2. Input:en is binary string |
1. The schema of the Sproto is very strong and flexible2. Writing proto files is very simple and very user-friendly 3. Easy to use |
Sproto (Nopack) |
Similar with Sproto |
Similar with Sproto |
|
Pbc-lua |
1.en=protobuf.encode ("Cookie.cookievalue", Cookievalue) 2.de=protobuf.decode ("Cookie.cookievalue", en) |
|
1. Input:cookievalue is table,2. Input en is binary |
This decode out of the table is lazy expansion, access to the table can be solved, or it will appear garbled |
Protobuf-c++ |
1. Str=bilin. Serialize (TB, ' cookie ') 2.bilin. Parse (str, ' Cookie ', #str) |
|
1. INPUT:TB is a table,2.input:str is binary string |
1. A change, more difficult to maintain 2. Time-consuming and compression-ratio effect is good, compared to other methods |
Lua-cjson |
1. En=cjson.encode (TB) 2.de=cjson.decode (en) |
1. INPUT:TB is a table,2. Input:en is Cjson string |
1. The space consumption is very large 2. It takes too much time to 3. Advantages: (For our existing use) No need to convert the program, that is, the solution is used |
2.1 Test Results
Library |
encode times (1M) |
decode Times (1M) |
size (byets) |
Sproto |
4. 6501181125641s |
one. 385328769684s |
139 |
sproto (nopack) |
4. 0319328308105s |
9. 9806959629059s |
272 |
Pbc-lua |
9. 3938179016113s |
7. 0795350074768s |
117 |
protobuf-c++ |
6. 0948710441589s |
9. 6896359920502s |
117 |
lua-cjson |
. 541377067566s |
. 335454940796s |
437 |
Test data: {"Pbid": [{"id":100188, "value": 3},{"id":100189, "Value": 3}, {"id":100190, "Value": 3}], "daily": [{" daily_id ": 1125," date_id ": [{" id ":100188," value ": 1}]},{" daily_id ": 1126," date_id ": [{" id ":100118," value ": 1 }]}], "Total": [{"id":100188, "value": 1}], "segments": [{"Type": 1, "ct":1415384160, "ttl":1415384160, "id" :100001}], "imp": [{"Win": 2, "bid": 3, "Time": 8160, "id":100188},{"Win": 2, "bid": 3, "Time": 8155, "id": 100182},{"Win": 2, "bid": 3, "Time": 8157, "id":100181}]}
3. Results analysis in the "2.0 Test Function Interface description" in the "note" column, has pointed out the advantages and disadvantages of these five methods, you can choose two scenarios as our solution to this problem:
- Scenario One: protobuf-c++, features: In time and space consumption, the advantages are obvious, but once there are new needs to change, maintenance is more complex;
- Scenario Two: Sproto, features: In time and space consumption, but also very advantageous, maintenance is very convenient, please refer to Sproto:https://github.com/cloudwu/sproto, PBC please refer to: https:// GITHUB.COM/CLOUDWU/PBC; Thank you.
JSON, Protobuf-c++,pbc,sproto performance testing and Solutions