fastjson和jackson的简单对比
来源:互联网 发布:微信假红包软件 编辑:程序博客网 时间:2024/06/03 19:25
代码片段(6)[全屏查看所有代码]
1. [代码]主测试程序
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
public
class
JsonParseTest {
public
static
void
main(String[] args)
throws
JsonProcessingException {
Monitoring.begin();
List<Corp> list = Lists.newArrayList();
for
(
int
i =
0
; i <
1000
; i++) {
list.add(fullObject(Corp.
class
));
}
Monitoring.end(
"生成数据"
);
Monitoring.begin();
jackson(list);
Monitoring.end(
"Jackson"
);
Monitoring.begin();
fastjson(list);
Monitoring.end(
"fastjson"
);
}
public
static
void
fastjson(List<Corp> list) {
for
(Corp corp : list) {
String string = JSON.toJSONString(corp);
}
}
public
static
void
jackson(List<Corp> list)
throws
JsonProcessingException {
for
(Corp corp : list) {
String string =
new
ObjectMapper().writeValueAsString(corp);
}
}
/**
* 填充一个对象(一般用于测试)
*/
public
static
<T> T fullObject(Class<T> cl) {
T t =
null
;
try
{
t = cl.newInstance();
Method methods[] = cl.getMethods();
for
(Method method : methods) {
// 如果是set方法,进行随机数据的填充
if
(method.getName().indexOf(
"set"
) ==
0
) {
Class param = method.getParameterTypes()[
0
];
if
(param.equals(String.
class
)) {
method.invoke(t, randomCodes(
5
));
}
else
if
(param.equals(Short.
class
)) {
method.invoke(t, (
short
)
new
Random().nextInt(
5
));
}
else
if
(param.equals(Float.
class
)) {
method.invoke(t,
new
Random().nextFloat());
}
else
if
(param.equals(Double.
class
)) {
method.invoke(t,
new
Random().nextDouble());
}
else
if
(param.equals(Integer.
class
)) {
method.invoke(t,
new
Random().nextInt(
10
));
}
else
if
(param.equals(Long.
class
)) {
method.invoke(t,
new
Random().nextLong());
}
else
if
(param.equals(Date.
class
)) {
method.invoke(t,
new
Date());
}
else
if
(param.equals(Timestamp.
class
)) {
method.invoke(t,
new
Timestamp(System.currentTimeMillis()));
}
else
if
(param.equals(java.sql.Date.
class
)) {
method.invoke(t,
new
java.sql.Date(System.currentTimeMillis()));
}
}
}
}
catch
(InstantiationException e) {
e.printStackTrace();
}
catch
(IllegalAccessException e) {
e.printStackTrace();
}
catch
(IllegalArgumentException e) {
e.printStackTrace();
}
catch
(InvocationTargetException e) {
e.printStackTrace();
}
return
t;
}
}
2. [代码]Corp类
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
public
class
Corp {
private
Long uid;
private
Integer corpGrade;
private
Integer cityId;
private
String name;
private
String EName;
private
String description;
private
String zipCode;
private
String tel;
private
String fax;
private
String EMail;
private
Integer isEmailOpen;
private
Integer EMailChecked;
private
Timestamp regDateOnGov;
private
String backroll;
private
String address;
private
String webStoreUrl;
private
Integer isNew;
private
Integer credit;
private
Integer activeDegrees;
private
Integer hits;
private
Integer isHitsRecord;
private
Timestamp regTimeOnZfa;
private
Integer corpType;
private
Integer corpMajorcategoryId;
private
Integer businessRoleId;
private
String keyword;
private
Integer developState;
private
String isAlert;
private
Integer advMemState;
private
Integer advStockState;
private
Integer allianceState;
private
Timestamp lastUpdateTime;
private
Integer corpMajorcategoryId1;
private
String keyword1;
private
Long certificatePic;
private
Integer isUpdateCharter;
private
Integer currcount;
private
Integer curronsale;
private
Integer curronhot;
private
Integer currniccount;
private
Integer currniconsale;
private
Integer currniconhot;
private
String buyProducts;
private
Integer isOpenShop;
private
Integer state;
private
String mainProduct;
private
String advBrandIds;
private
String feature;
private
Integer category;
private
Integer contactFlag;
private
String fastPassage;
//省略getter、setter方法
}
3. [代码]小的监控管理类
1
2
3
4
5
6
7
8
9
10
11
12
public
class
Monitoring {
private
static
ThreadLocal<Long> begin =
new
ThreadLocal<Long>();
public
static
void
begin() {
begin.set(System.currentTimeMillis());
}
public
static
void
end(String name) {
double
time = (System.currentTimeMillis() - begin.get()) /
1000.0
;
System.out.println(name +
"所用时间(秒):"
+ time);
}
}
4. [图片] 1000.png
5. [图片] 5000.png
6. [图片] 10000.png
0 0
- fastjson和jackson的简单对比
- jackson和fastjson的效率对比:
- Jackson和fastjson简单用法及性能对比
- FastJson、Jackson、Gson、Json的效率简单对比
- FastJSON、Gson和Jackson性能对比
- FastJSON、Gson和Jackson性能对比
- FastJSON、Gson和Jackson性能对比
- FastJSON、Gson和Jackson性能对比
- FastJSON、Gson和Jackson性能对比
- FastJSON、Gson和Jackson性能对比
- FastJSON、Gson和Jackson性能对比
- Jackson,Gson,Fastjson的解析时间对比
- FastJson和Jackson的使用
- FastJSON、Gson和Jackson性能对比和共同缺点,注意事项
- FastJSON、Gson和Jackson性能对比和共同缺点,注意事项
- FastJSON 原理剖析 以及 和 Jackson的对比 who is the most fast!
- FastJSON 原理剖析 以及 和 Jackson的对比 who is the most fast!
- json性能对比 fastjson jackson
- Win10或Win8下ObjectARX2015 Wizard向导创建项目失败解决方法
- 利用commons-dbutils获取xml内容
- 学习日记 --泛型
- Java程序片段 之动态生成表格
- (ZT)Change default Program Files installation directory location in Windows
- fastjson和jackson的简单对比
- Java笔记
- 软件开发--面试笔试题集锦
- LeetCode 113. Path Sum II
- [BZOJ2196]Brownie Slicing 二分答案
- NotePad++快捷键大全
- 数据库技术
- #include< > 和 #include” ” 的区别以及绝对地址引用\\以及cvLoadImage和imread
- Huffman编解码