XML跟Json的一些对比
来源:互联网 发布:js设置元素display为'' 编辑:程序博客网 时间:2024/05/16 10:56
xml、json序列化反序列化时间对比
结果:单位(毫秒)
xml:30810
fastjson:859
gson:1482
源代码:
private void compTime() {Person p = new Person();p.setAge(23);p.setName("李志鹏");p.setBirthday(new Date());long count = 100000;System.out.println("-----------------------compTime-----------------------");long startMili;long endMili;startMili = System.currentTimeMillis();for (int i = 0; i < count; i++) {Writer writer = new StringWriter();JAXB.marshal(p, writer);String xml = writer.toString();Reader reader = new StringReader(xml);Person retP = JAXB.unmarshal(reader, p.getClass());}endMili = System.currentTimeMillis();System.out.println("xml:" + (endMili - startMili));startMili = System.currentTimeMillis();for (int i = 0; i < count; i++) {String json = JSON.toJSONString(p);Person retP = JSON.parseObject(json, new TypeReference<Person>() {});}endMili = System.currentTimeMillis();System.out.println("fastjson:" + (endMili - startMili));startMili = System.currentTimeMillis();Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();for (int i = 0; i < count; i++) {String json = gson.toJson(p);Person retP = gson.fromJson(json,new TypeToken<Person>() {}.getType());}endMili = System.currentTimeMillis();System.out.println("gson:" + (endMili - startMili));}
序列化同一对象形成的数据大小对比:
结果:单位:字节
json:368
xml:568
源代码:
private void compSize() {Map<String, Object> map = TestPrepareData.getStudentAndTeacher();String json = JSON.toJSONString(map);String xml = XmlJson.json2xml(json);System.out.println("json:" + json);System.out.println("xml:" + xml);System.out.println("json:" + json.length());System.out.println("xml:" + xml.length());}
- XML跟Json的一些对比
- xml与json的对比
- XML与JSON的对比
- xml与json的对比
- XML与JSON的对比
- 总结:windows跟linux的一些对比
- AJAX跟JSON的一些理解
- xml解析和json解析的对比
- xml与json的对比(转)
- json与xml对比
- json与xml对比
- json与xml对比
- XML和JSON对比
- json与xml对比
- Json与Xml对比
- XML与JSON数据对比
- protobuf,json,xml,binary,Thrift之间的对比
- protobuf,json,xml,binary,Thrift之间的对比 .
- js判读浏览器是否支持html5的canvas
- java synchronized详解 三
- 推荐个学习webkit css的网站
- archlinux 连接网络,及使用ssh登录。
- Android飞行模式的打开与关闭
- XML跟Json的一些对比
- MFC--非模式对话框程序(mfc框架)
- hdu 1879 裸最小生成树
- C++ 弹出U盘
- DOS中常用的网络命令
- NodeJs 安装 Express框架报错的解决办法
- 显示各种类型窗口
- TCP/IP 协议简单分析
- 无题