mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-18 18:15:46 +00:00
test[benchmark]: fastjson2 test
This commit is contained in:
1 parent
59d8ce0815
commit
64a3526cc0
1 file changed
+39
@@ -14,6 +14,7 @@
|
|||||||
package com.zfoo.protocol;
|
package com.zfoo.protocol;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.alibaba.fastjson2.JSONB;
|
import com.alibaba.fastjson2.JSONB;
|
||||||
import com.esotericsoftware.kryo.Kryo;
|
import com.esotericsoftware.kryo.Kryo;
|
||||||
import com.esotericsoftware.kryo.io.Input;
|
import com.esotericsoftware.kryo.io.Input;
|
||||||
@@ -70,6 +71,7 @@ public class BenchmarkTesting {
|
|||||||
|
|
||||||
zfooTest();
|
zfooTest();
|
||||||
jsonbTest();
|
jsonbTest();
|
||||||
|
fastJson2Test();
|
||||||
furyTest();
|
furyTest();
|
||||||
kryoTest();
|
kryoTest();
|
||||||
protobufTest();
|
protobufTest();
|
||||||
@@ -220,6 +222,43 @@ public class BenchmarkTesting {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fastJson2Test() {
|
||||||
|
try {
|
||||||
|
// 序列化和反序列化简单对象
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
for (int i = 0; i < benchmark; i++) {
|
||||||
|
var str = JSON.toJSONString(simpleObject);
|
||||||
|
var mess = JSON.parseObject(str, SimpleObject.class);
|
||||||
|
|
||||||
|
// 这种通过流写入的方式速度奇慢
|
||||||
|
// JSONB.writeTo(output, normalObject);
|
||||||
|
// var mess = JSONB.parseObject(input, NormalObject.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(StringUtils.format("[fastjson2] [简单对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), JSON.toJSONString(simpleObject).getBytes().length, System.currentTimeMillis() - startTime));
|
||||||
|
|
||||||
|
// 序列化和反序列化常规对象
|
||||||
|
startTime = System.currentTimeMillis();
|
||||||
|
for (int i = 0; i < benchmark; i++) {
|
||||||
|
var str = JSON.toJSONString(normalObject);
|
||||||
|
var mess = JSON.parseObject(str, NormalObject.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(StringUtils.format("[fastjson2] [常规对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(),JSON.toJSONString(normalObject).getBytes().length,System.currentTimeMillis() - startTime));
|
||||||
|
|
||||||
|
// 序列化和反序列化复杂对象
|
||||||
|
startTime = System.currentTimeMillis();
|
||||||
|
for (int i = 0; i < benchmark; i++) {
|
||||||
|
var str = JSON.toJSONString(complexObject);
|
||||||
|
var mess = JSON.parseObject(str, ComplexObject.class);
|
||||||
|
}
|
||||||
|
System.out.println(StringUtils.format("[fastjson2] [复杂对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), JSON.toJSONString(complexObject).getBytes().length, System.currentTimeMillis() - startTime));
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void kryoTest() {
|
public void kryoTest() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in new issue
Block a user