Skip to content

Commit

Permalink
test[fastjson2]: jsonb test
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Nov 28, 2023
1 parent 0991fa3 commit 6df23b5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions protocol/src/test/java/com/zfoo/protocol/BenchmarkTesting.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,13 @@ public void jsonbTest() {
output.reset();
var bytes = JSONB.toBytes(simpleObject);
var mess = JSONB.parseObject(bytes, SimpleObject.class);

// 次方式速度奇慢
// JSONB.writeTo(output, normalObject);
// var mess = JSONB.parseObject(input, NormalObject.class);
}

System.out.println(StringUtils.format("[fastjsonb] [简单对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), output.position(), System.currentTimeMillis() - startTime));
System.out.println(StringUtils.format("[fastjsonb] [简单对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), JSONB.toBytes(simpleObject).length, System.currentTimeMillis() - startTime));

// 序列化和反序列化常规对象
startTime = System.currentTimeMillis();
Expand All @@ -206,7 +210,7 @@ public void jsonbTest() {
var mess = JSONB.parseObject(bytes, NormalObject.class);
}

System.out.println(StringUtils.format("[fastjsonb] [常规对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), output.position(), System.currentTimeMillis() - startTime));
System.out.println(StringUtils.format("[fastjsonb] [常规对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), JSONB.toBytes(normalObject).length, System.currentTimeMillis() - startTime));

// 序列化和反序列化复杂对象
startTime = System.currentTimeMillis();
Expand All @@ -217,7 +221,7 @@ public void jsonbTest() {
var bytes = JSONB.toBytes(complexObject);
var mess = JSONB.parseObject(bytes, ComplexObject.class);
}
System.out.println(StringUtils.format("[fastjsonb] [复杂对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), output.position(), System.currentTimeMillis() - startTime));
System.out.println(StringUtils.format("[fastjsonb] [复杂对象] [thread:{}] [size:{}] [time:{}]", Thread.currentThread().getName(), JSONB.toBytes(complexObject).length, System.currentTimeMillis() - startTime));
} catch (Exception e) {
System.err.println(e.getMessage());
}
Expand Down

0 comments on commit 6df23b5

Please sign in to comment.