最近用到Json来传输数据,找到两个比较简单的工具 Gson 和 FastJson
随便测试一下两个工具的效率~ 1 package com.json.fast; import java.util.ArrayList;
import java.util.List; import com.alibaba.fastjson.JSON;
import com.demo.module.Student;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; public class FastJson {
public static void main(String[] args) { List<Student> list=new ArrayList<Student>(); for (int i = 0; i < 500000; i++) {
Student student=new Student();
student.setId(i);
student.setName("Name"+i);
student.setAge(i);
student.setSex("boy"); list.add(student);
} String json=JSON.toJSONString(list);
for (int i = 0; i < 10; i++) {
long time_start = System.currentTimeMillis();
JSON.toJSONString(list);
long time_end = System.currentTimeMillis();
System.out.println("FastJson to JSON 用时:"+(time_end-time_start));
}
System.out.println();
for (int i = 0; i < 10; i++) {
long time_start = System.currentTimeMillis();
JSON.parseArray(json, Student.class);
long time_end = System.currentTimeMillis();
System.out.println("FastJson to List 用时:"+(time_end-time_start));
}
System.out.println(); Gson gson=new Gson();
for (int i = 0; i < 10; i++) {
long time_startg = System.currentTimeMillis();
gson.toJson(list);
long time_endg = System.currentTimeMillis();
System.out.println("Gson to JSON 用时:"+(time_endg-time_startg));
}
System.out.println();
for (int i = 0; i < 10; i++) {
long time_startg = System.currentTimeMillis();
gson.fromJson(json,new TypeToken<List<Student>>(){}.getType());
long time_endg = System.currentTimeMillis();
System.out.println("Gson to List 用时:"+(time_endg-time_startg));
}
}
}
LIST to JSON 用时比较
FastJson to JSON 用时:1188
FastJson to JSON 用时:1034
FastJson to JSON 用时:1201
FastJson to JSON 用时:1450
FastJson to JSON 用时:712
FastJson to JSON 用时:1156
FastJson to JSON 用时:695
FastJson to JSON 用时:1142
FastJson to JSON 用时:680
FastJson to JSON 用时:1206 Gson to JSON 用时:1079
Gson to JSON 用时:1108
Gson to JSON 用时:905
Gson to JSON 用时:1097
Gson to JSON 用时:903
Gson to JSON 用时:1056
Gson to JSON 用时:905
Gson to JSON 用时:903
Gson to JSON 用时:1113
Gson to JSON 用时:897
JSON to LIST 用时比较 

FastJson to List 用时:351
FastJson to List 用时:222
FastJson to List 用时:189
FastJson to List 用时:177
FastJson to List 用时:281
FastJson to List 用时:349
FastJson to List 用时:258
FastJson to List 用时:226
FastJson to List 用时:213
FastJson to List 用时:201 Gson to List 用时:1305
Gson to List 用时:745
Gson to List 用时:790
Gson to List 用时:864
Gson to List 用时:886
Gson to List 用时:1168
Gson to List 用时:907
Gson to List 用时:796
Gson to List 用时:914
Gson to List 用时:1206
 package com.demo.module;

 public class Student {
private int id;
private String name;
private int age;
private String sex; public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
} }

不足之处请大家指点 . . .

fastJson 下载:链接: http://pan.baidu.com/s/1kT7hVnx

gson     下载:链接: http://pan.baidu.com/s/1sjLiQRF

FastJson与Gson小测试的更多相关文章

  1. FastJSON、Gson和Jackson性能对比

    Java处理JSON数据有三个比较流行的类库FastJSON.Gson和Jackson.本文将测试这三个类库在JSON序列化和反序列化的方面表现,主要测试JSON序列化和反序列化的速度.为了防止由于内 ...

  2. FastJson和Gson和Json数据解析分析和用法

    首先分析下目前号称最快的FastJson,这个是所有人都验证过的,解析速度确实比较快,不过也需要根据数据量来看,数据量小的时候,Gson性能要稍微优于FastJson,但在数据量大解析的情况下,Fas ...

  3. FastJSON、Gson、Jackson(简单了解使用)

    下载地址(maven) Jackson:http://mvnrepository.com/search?q=jackson FastJson:http://mvnrepository.com/sear ...

  4. Fastjson和Gson零碎总结

    一:用于测试的类 User类 import lombok.Data; import lombok.experimental.Accessors; /** * @author silentdoer * ...

  5. Cad 二次开发关于SelectCrossingPolygon和SelectFence返回结果Status为error的小测试

    CAD2008的二次开发,有个很奇怪的现象,只要你选择的点集不在当前视图上SelectCrossingPolygon和SelectFence返回结果Status就会为error,所以要获取正确的结果, ...

  6. python 程序小测试

    python 程序小测试 对之前写的程序做简单的小测试 ... # -*- encoding:utf-8 -*- ''' 对所写程序做简单的测试 @author: bpf ''' def GameOv ...

  7. PHP中使用PDO操作事务的一些小测试

    关于事务的问题,我们就不多解释了,以后在学习 MySQL 的相关内容时再深入的了解.今天我们主要是对 PDO 中操作事务的一些小测试,或许能发现一些比较好玩的内容. 在 MyISAM 上使用事务会怎么 ...

  8. Android进阶笔记17:3种JSON解析工具(org.json、fastjson、gson)

    一. 目前解析json有三种工具:org.json(Java常用的解析),fastjson(阿里巴巴工程师开发的),Gson(Google官网出的),其中解析速度最快的是Gson. 3种json工具下 ...

  9. 使用fastjson,gson解析null值的时候键保留

    由于业务需求...所以查阅资料,总结如下: 使用gson实现方法:只需要把new Gson()改为: new GsonBuilder().serializeNulls().create(); 就可以了 ...

随机推荐

  1. MVC4.0 WebApi如何自定义返回数据类型

    1.客户端可以通过HTTP Accept消息头来通知服务器客户端想要什么样的MIME类型数据,例如:application/json则代表告诉服务器想要的是Json数据 2.服务器端撇开客户端的请求类 ...

  2. 如何安装altium designer 10

    http://jingyan.baidu.com/article/4dc4084881e2bdc8d946f1f3.html

  3. Python实现Apriori

    Python实现Apriori 运行环境 Pyhton3 计算过程 st=>start: 开始 e=>end: 结束 op1=>operation: 读入数据 op2=>ope ...

  4. mysql 创建一个用户,指定一个数据库

    mysql 创建一个用户 hail,密码 hail,指定一个数据库 haildb 给 hail mysql -u root -p password use mysql; insert into use ...

  5. 骇客(Hacker)用语

                     什么是TCP/IP 是一种网络通信协议,他规范了网络上所有的通信设备,尤其是一个主机与另一个主机之间的数据往来格式以及传送方式.,TCP/IP是INTERNET的基础 ...

  6. Xcode 7遇到 App Transport Security has blocked a cleartext HTTP 错误

    今天用Xcode 7 创建新项目用到 URL 发送请求时,报下面的错: “App Transport Security has blocked a cleartext HTTP (http://) r ...

  7. poj 1325 Machine Schedule 最小点覆盖

    题目链接:http://poj.org/problem?id=1325 As we all know, machine scheduling is a very classical problem i ...

  8. jquery $.ajax方法

    $.ajax({ timeout: 3000, cache:false, global:false, type: "POST", url: WEB_URL+"/logic ...

  9. spring framework项目源码github托管地址

    方法一:直接下载,github托管地址:http://repo.spring.io/simple/libs-release-local/org/springframework/spring/ 方法二: ...

  10. Poj 2349 Arctic Network 分类: Brush Mode 2014-07-20 09:31 93人阅读 评论(0) 收藏

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9557   Accepted: 3187 De ...