From 6df23b55fa2f8b1be6d2164c95462256be6daac2 Mon Sep 17 00:00:00 2001 From: godotg Date: Tue, 28 Nov 2023 11:39:53 +0800 Subject: [PATCH] test[fastjson2]: jsonb test --- .../test/java/com/zfoo/protocol/BenchmarkTesting.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/protocol/src/test/java/com/zfoo/protocol/BenchmarkTesting.java b/protocol/src/test/java/com/zfoo/protocol/BenchmarkTesting.java index c2d1974d4..62c22d672 100644 --- a/protocol/src/test/java/com/zfoo/protocol/BenchmarkTesting.java +++ b/protocol/src/test/java/com/zfoo/protocol/BenchmarkTesting.java @@ -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(); @@ -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(); @@ -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()); }