diff --git a/README.md b/README.md index 25adcf6..d07cdc0 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,21 @@ jvm-serializer ============== +## Environment +### Hardware: +#### Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz,4 core 8G mem +### Software: +#### kernel 3.13.0-43-generic,x86_64 GNU/Linux +#### Java HotSpot(TM) 64-Bit Server VM 1.7.0_25 + +## Description +This project is a function and performance benchmark test for kyro3,fastjson and hessian codec(Serialize and Deserialize).which are most popular non-schema Serialize and Deserialize tools nowadays. +### Test case +#### 1.After 12000 times warm up op,do 5000 times codec loop.recycle this procedure 10 times. +#### 2.Consider some special java type,such as BitEnum,EnumSet etc... +### Report +| Tool | size | cost(ms) | +| ------------- |-------------| ----------| +| Kryo3 | 79 | 79 | +| Fastjson | 340 | 196 | +| Hessian4 | 718 | 342 | + diff --git a/src/main/java/com/creative/commons/utils/KryoCodec.java b/src/main/java/com/creative/commons/utils/KryoCodec.java index 1fcbda5..3acf01f 100644 --- a/src/main/java/com/creative/commons/utils/KryoCodec.java +++ b/src/main/java/com/creative/commons/utils/KryoCodec.java @@ -88,8 +88,8 @@ public static synchronized void registerClass(Class className, Serializer idList.add(id); } - public static synchronized void register(Class className){ - getKryo().register(className); + public static synchronized void register(Class className) { + getKryo().register(className); } public static Kryo getKryo() { @@ -102,7 +102,8 @@ public static Object decode(byte[] bytes) throws Exception { } public static byte[] encode(Object object) throws Exception { - Output output = new Output(1024 * 1024); + //4K + Output output = new Output(4096); getKryo().writeClassAndObject(output, object); return output.toBytes(); } diff --git a/src/test/java/com/creative/commons/utils/HessianCodecTest.java b/src/test/java/com/creative/commons/utils/HessianCodecTest.java index 16ebad6..5fccc4c 100644 --- a/src/test/java/com/creative/commons/utils/HessianCodecTest.java +++ b/src/test/java/com/creative/commons/utils/HessianCodecTest.java @@ -22,6 +22,7 @@ public class HessianCodecTest extends CodecTest{ public void hessianCodecTest() throws Throwable { Father father = new Father(); byte[] obj1 = HessianCodec.encode(father); + System.out.println(obj1.length); Father fatherCopy = (Father) HessianCodec.decode(obj1); //Timestamp type is null diff --git a/src/test/java/com/creative/commons/utils/JsonCodecTest.java b/src/test/java/com/creative/commons/utils/JsonCodecTest.java index 84d6795..875b409 100644 --- a/src/test/java/com/creative/commons/utils/JsonCodecTest.java +++ b/src/test/java/com/creative/commons/utils/JsonCodecTest.java @@ -14,6 +14,7 @@ public class JsonCodecTest extends CodecTest{ public void jsonCodecTest() { Father father = new Father(); byte[] obj1 = JsonCodec.encode(father); + System.out.println(obj1.length); Father fatherCopy = JsonCodec.decode(obj1, Father.class); //Timestamp type diff --git a/src/test/java/com/creative/commons/utils/KryoCodecTest.java b/src/test/java/com/creative/commons/utils/KryoCodecTest.java index f4dbc32..c02fa00 100644 --- a/src/test/java/com/creative/commons/utils/KryoCodecTest.java +++ b/src/test/java/com/creative/commons/utils/KryoCodecTest.java @@ -5,11 +5,12 @@ import com.creative.model.Message; import com.creative.model.Son; import com.google.common.base.Stopwatch; +import org.junit.Assert; import org.junit.Test; import java.util.concurrent.TimeUnit; -public class KryoCodecTest extends CodecTest{ +public class KryoCodecTest extends CodecTest { @Test public void kryoCodecMultiTest() throws Exception { //Warmup @@ -50,8 +51,11 @@ public void kyroCodecTest() throws Exception { Father father = new Father(); byte[] obj1 = KryoCodec.encode(father); + System.out.println(obj1.length); Father fatherCopy = (Father) KryoCodec.decode(obj1); + Assert.assertEquals(father, fatherCopy); + //Timestamp type //System.out.println(fatherCopy.getLocation_time()); //System.out.println(father.getLocation_time());