Skip to content

Commit

Permalink
add codec size test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouxinyu committed Aug 12, 2016
1 parent 1b7ce62 commit f230451
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.io.IOException;

public class JsonCodecTest extends CodecTest{
public class FastJsonCodecTest extends CodecTest{

@Test
public void jsonCodecSizeTest() throws Throwable {
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/com/creative/commons/utils/KryoCodecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.junit.Test;
import org.openjdk.jmh.annotations.Benchmark;

import java.util.concurrent.TimeUnit;

public class KryoCodecTest extends CodecTest {

@Test
Expand All @@ -22,6 +24,25 @@ public void kryoCodecMultiTest() throws Exception {
kryoEncodeAndDecode();
}

@Test
public void testThrpt() throws InterruptedException {
final int[] count = {0};
Thread t = new Thread(() -> {
while (!Thread.interrupted()) {
try {
kryoEncodeAndDecode();
count[0]++;
} catch (Exception e) {
e.printStackTrace();
}
}
});
t.start();
TimeUnit.SECONDS.sleep(10);
t.interrupt();
System.out.println(count[0] / 10);
}

private void kryoEncodeAndDecode() throws Exception {
KryoCodec.register(Message.class);
KryoCodec.register(Father.class);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/creative/commons/utils/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(MsgPackCodecTest.class.getSimpleName())
.include(KryoCodecTest.class.getSimpleName())
.include(JsonCodecTest.class.getSimpleName())
.include(FastJsonCodecTest.class.getSimpleName())
.include(JdkCodecTest.class.getSimpleName())
.include(HessianCodecTest.class.getSimpleName())
.forks(2).measurementIterations(
10).warmupIterations(10).build();
.forks(1).measurementIterations(
3).warmupIterations(3).shouldDoGC(true).build();

new Runner(opt).run();
}
Expand Down
25 changes: 7 additions & 18 deletions src/test/java/com/creative/commons/utils/MsgPackCodecTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.creative.commons.utils;

import com.creative.model.Message;
import org.junit.Test;
import org.openjdk.jmh.annotations.Benchmark;

import java.io.IOException;
Expand All @@ -15,6 +16,12 @@ public void measureName() throws IOException {
msgPackEncodeAndDecode();
}

@Test
public void msgPackCodecSizeTest() {
byte[] obj1 = MsgPackCodec.encode(msg1);
System.out.println(obj1.length);
}


private void msgPackEncodeAndDecode() throws IOException {
byte[] obj1 = MsgPackCodec.encode(msg1);
Expand All @@ -28,21 +35,3 @@ private void msgPackEncodeAndDecode() throws IOException {
}
}

@org.msgpack.annotation.Message
class NewMessage {
String a;

public NewMessage() {
}

public NewMessage(String a) {
this.a = a;
}

@Override
public String toString() {
return "NewMessage{" +
"a='" + a + '\'' +
'}';
}
}

0 comments on commit f230451

Please sign in to comment.