java序列化和反序列化性能比较

来源:互联网 发布:新网域名转移密码 编辑:程序博客网 时间:2024/05/16 21:54

Benchmarks (2011-07-13)

WARNING: Benchmarks can be misleading.

  • These tests use a specific data value (TestValue). A different data value will yield different results.
  • The tools don’t all do the exact same thing (ToolBehavior). Some of them take shortcuts to improve performance; some of them require the programmer to do more work, etc.
  • Different hardware and software environments will yield different results.
  • We don’t take memory usage into account.

In short, before you make a decision on which tool to use, make sure you try it out in an environment you care about. To start, download the benchmark code and run it onyour hardware with data valuesyou care about.

Setup

Hardware: Intel I7 2600k (3.4 – 3.8Ghz)
Software: Sun JRE 1.6.0_26 (64-bit server VM), Ubuntu 11.04
JVM options: -Xmx16m -server

Data value being tested: TestValue.

Version of the benchmarking code: Git tree

Methodology:

  • Before taking measurements, we warm things up by running the test several times.
  • For a test, measure the time taken to perform 2000 operations (serialization, deserialization, etc.). Then divide the result by 2000.
  • Run each test 500 times and report the best result.
  • Look at the code for more details. BenchmarkRunner.java

Tool Versions ( lib/):

  • scala 2.8.0-rc1
  • sbinary 0.3.1-SNAPSHOT
  • hessian 4.0.3
  • kryo 1.03
  • protobuf 2.3.0
  • activemq-protobuf 1.1-SNAPSHOT
  • protostuff 1.0.0
  • thrift 0.4.0
  • avro 1.5.0
  • msgpack 0.5.2
  • jackson 1.8.1
  • google-gson 1.7.1
  • svenson 1.4.0
  • json-lib 2.4
  • fastjson 1.0.5
  • json-simple 1.1
  • json-smart 1.0.8
  • json.org ref-2011.06.21
  • json-ij 0.2.7
  • argo 2.10
  • bson4jackson 1.1.0
  • bson mongo 2.4
  • woodstox 4.0.7
  • aalto 0.9.5
  • fast-infoset 1.2.6
  • xstream 1.3.1
  • javolution 5.5.1
  • Flexjson 2.1
  • JSONPath (from 2011.06.23 code base)

Charts

(“manual” labels in charts shortened to “M”.)

Total Time (“total”)

Create an object, serialize it to a byte array, then deserialize it back to an object.

Serialization Time (“ser”)

Create an object, serialize it to a byte array.

  • Java’s built-in serializer faithfully represents arbitrary object graphs, which hurts performance. All the other serializers flatten the structure out to a tree.

Deserialization Time (“deser+deep”)

Often the most expensive operation. To make a fair comparison, all fields of the deserialized instances are accessed – this forces lazy deserializers to really do their work. The raw data below shows additional measurements for deserialization.

Serialized Size (“size”)

The size of the serialized data. These numbers may vary depending on the exact data value being used.

  • Java’s built-in serializer stores the full class name in serialized form. So you don’t need to know ahead of time what kind of object you’re reading in.
  • The ‘scala’ test, which uses Java’s built-in serialization, yields a larger serialized representation because it usually creates more Java classes under the hood.

Serialization Compressed Size (“size+dfl”)

The size of the serialized data compressed with Java’s built-in implementation ofDEFLATE (zlib).

Object Creation Time (“create”)

Object creation is not so meaningful since it takes in average 100 nano to create an object. However, the different tools vary in how “fancy” their objects are. Some just create a plain Java class and let you access fields directly, while others have set/get methods, while others use the “builder” pattern.

  • Protobuf and Thrift use the “builder” pattern to create objects, which makes the operation more expensive.
  • Avro stores Strings in UTF8 form. The time taken to convert from Java “String” values toUTF-8 is included under “create”, “ser”, “deser+shal”, and “deser+deep”, which isn’t quite representative of real-world usage. Real code that uses Avro might be able to keep strings inUTF-8 form, thus avoiding the need to convert back and forth (in which case the “ser+same” and “deser” results might be more accurate reflections of Avro’s performance).

Numbers

Times are in nanoseconds, sizes are in bytes.

                                create     ser   +same   deser   +shal   +deep   total   size  +dfljava-built-in                       109    6338    5624   33940   33967   34203   40542    889   514java-manual                         104    1022     919     725     767     830    1852    255   147scala/java-built-in                 341    9639    8105   49672   50273   50364   60003   1312   700scala/sbinary                       308    2275    2052    1531    1635    1884    4160    255   147hessian                             110    4772    4193    6995    7104    7162   11934    501   313kryo                                117    1325    1210    1398    1425    1486    2811    233   147kryo-opt                            112    1126    1011    1242    1286    1336    2462    219   135kryo-manual                         118    1083     960    1021    1065    1097    2180    219   132protobuf                            294    2378    1007    1088    1124    1382    3760    239   149protobuf/activemq+alt               193    2502       5       7     710    1482    3984    239   149protostuff                          139     667     530    1055    1083    1171    1838    239   150protostuff-manual                   118     637     537     934     973    1050    1687    239   150protostuff-runtime                  119     859     759    1260    1303    1336    2195    241   151protobuf/protostuff                 156     709     581    1071    1100    1164    1873    239   149thrift                              234    2548    2332    1351    1381    1471    4019    349   197thrift-compact                      219    2395    2138    1470    1537    1646    4041    240   148avro                                188    2625    2442    1400    1818    2368    4993    221   133avro-generic                        544    2892    2331    1150    1731    2404    5297    221   133msgpack/dynamic                     119    1762    1662    1317    1557    1550    3312    233   146json/jackson-manual                 112    1426    1307    2180    2192    2285    3711    468   253json/jackson-manual/tree            122    2948    2861    3396    3442    3578    6525    485   259json/jackson-manual/tree-strings    114    4085    3841    4406    4404    4519    8605    485   259json/jackson-databind               115    2293    2074    3236    3299    3422    5715    503   271json/jackson-databind-strings       123    3104    2901    4252    4359    4476    7580    503   271json/protostuff-manual              119    1604    1422    2147    2186    2262    3866    449   233json/protostuff-runtime             115    2051    1835    2536    2576    2689    4740    469   243json/protobuf                       285   12306   11607   83253   83620   84137   96444    488   253json/google-gson/manual             112    6097    5964    5449    5504    5548   11645    468   253json/google-gson/manual/tree        121    8297    8676   10451   10530   10955   19252    485   259json/google-gson/databind           118   28208   27836   32526   32719   32894   61102    486   259json/svenson-databind               115    5532    5267   15785   15747   15865   21396    495   268json/flexjson/databind              116   27763   27559   70925   71118   71819   99582    503   273json/json-lib-databind              118   39954   43557  118112  116565  121168  161123    485   263json/fastjson-databind              116    2942    2773    4194    4234    4362    7303    478   254json/json.simple/manual             122    8645    8319   10716   10642   10882   19527    495   269json/json.simple/manual/tree        118    8336    8480   11747   11680   11906   20242    495   269json/json-smart/manual/tree         117    7060    6810    4282    4279    4390   11450    495   269json/org.json/manual/tree           117    8930    8797   10497   10813   11077   20007    485   259json/jsonij-jpath                   117   44052   45082   16807   16711   16699   60751    478   254json/jsonij-manual/tree             119   44208   43262    8330    8523    8547   52755    478   254json/argo-manual/tree               121  125007  125486   19256   19543   19323  144330    485   263json/jsonpath/json.simple           118    8564    8336  354889  351264  376660  385224    495   269bson/jackson-manual                 124    5114    5015    6690    6766    6930   12043    495   278bson/jackson-databind               124    6720    6217    8256    8285    8461   15181    519   295bson/mongodb                        117    4416    4268   13829   15456   15132   19548    495   278smile/jackson-manual                127    1263    1126    1473    1503    1579    2842    341   244smile/jackson-databind              127    2162    2021    2589    2651    2768    4929    364   259smile/protostuff-manual             120    1467    1350    1687    1740    1793    3261    321   229smile/protostuff-runtime            120    1693    1574    1958    1993    2071    3764    335   235xml/woodstox-manual                 123    4185    3985    5065    5134    5273    9457    653   304xml/aalto-manual                    127    2459    2346    3567    3631    3801    6260    653   304xml/fastinfo-manual                 124    7791    7435    7565    7826    7625   15417    377   284xml/xstream+c                       120    6694    5985   22916   23519   21833   28527    487   244xml/xstream+c-woodstox              120    6177    5568   12877   13091   13067   19244    525   273xml/xstream+c-aalto                 119    5135    4548   10474   10635   10692   15827    525   273xml/xstream+c-fastinfo              120    9762    8671   10533   10441   10910   20672    345   264xml/jackson-databind/aalto          118    4252    3891    6308    6460    6652   10903    712   298xml/javolution                      122    7859    7473    8875    9031    9169   17028    504   263

Columns:

  • create: create an object (using the classes specified by the serialization tool)
  • ser: create an object and serialize it
  • +same: serialize the same object (i.e. doesn’t include creation time)
  • deser: deserialize an object
  • +shal: deserialize an object and access the top-level fields
  • +deep: deserialize an object and access all the fields
  • total: create + serialize + deserialize and access all fields
  • size: the size of the serialized data
  • +dfl: the size of the serialized data compressed with Java’s built-in implementation ofDEFLATE (zlib)


参见:https://github.com/eishay/jvm-serializers/wiki



原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 苹果手机迅雷下载不了的资源怎么办 快手官方私信你的作品违规了怎么办 顺丰生鲜速配食物坏了怎么办 半年汽车没有年检 交警抓到怎么办 没年检的车子被交警抓到怎么办 去年检的路上被交警抓了怎么办 微信聊天界面群聊删除找不到怎么办 微博抽奖的奖品没发货怎么办 两个微信号绑了一个手机号怎么办 欧月玫瑰花朵叶子上有白粉怎么办 进对方空间被挡不想让他知道怎么办 qq上买东西给钱了对方没给怎么办 微信钱包手势密码忘记了怎么办 买家一起拍了两件宝贝怎么办 宿雾航空付款无法显示验证码怎么办 不小心把购物车的东西删了怎么办 微信在别人电脑登录忘退出怎么办 微信电脑版忘了退出怎么办 给微商交了定金不给退怎么办 方舟手游飞龙驯服时间不够怎么办 淘宝上买了假货找不到商家怎么办 魅蓝手机一直在开机画面怎么办 在实体店买的手机想退怎么办 淘宝买了东西发货了不想要了怎么办 快递已经发货了不想要了怎么办 锤子手机买了不到十天碎屏了怎么办 唯品会新人专享优惠卷过期了怎么办 我微信被系统说赌博登陆不起怎么办 平湖新居民积分卡怎么办办好办吗 电话卡插上去只能打紧急电话怎么办 不小心充错q币了怎么办 液相色谱柱堵了怎么办处理柱子 扣扣空间宠物消消87关怎么办 微信钱包里的钱忘记密码了怎么办 支付宝绑定银行卡要验证码怎么办 微信红包超出20万限额怎么办 微信充电信的号码话费没到账怎么办 农业银行手机银行转账转错了怎么办 微信钱包里的零钱不见了怎么办 买家说支付宝没钱要微信付钱怎么办 微信红包没绑卡密码忘了怎么办