Skip to content

Commit

Permalink
finish report
Browse files Browse the repository at this point in the history
  • Loading branch information
Gosling committed Jan 6, 2015
1 parent e5b5a4c commit 490ef49
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 |

7 changes: 4 additions & 3 deletions src/main/java/com/creative/commons/utils/KryoCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/com/creative/commons/utils/KryoCodecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 490ef49

Please sign in to comment.