1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| package org.liuyehcf.jmh.serialize;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder;
import java.util.HashMap; import java.util.Map; import java.util.UUID; import java.util.concurrent.TimeUnit;
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Fork(1) @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) public class SerializerCmp {
private static final Map<String, String> MAP_SIZE_1 = new HashMap<>(); private static final Map<String, String> MAP_SIZE_10 = new HashMap<>(); private static final Map<String, String> MAP_SIZE_100 = new HashMap<>();
static { for (int i = 0; i < 1; i++) { MAP_SIZE_1.put(UUID.randomUUID().toString(), UUID.randomUUID().toString()); }
for (int i = 0; i < 10; i++) { MAP_SIZE_10.put(UUID.randomUUID().toString(), UUID.randomUUID().toString()); }
for (int i = 0; i < 100; i++) { MAP_SIZE_100.put(UUID.randomUUID().toString(), UUID.randomUUID().toString()); } }
@Benchmark public void json_size_1() { CloneUtils.jsonClone(MAP_SIZE_1); }
@Benchmark public void kryo_size_1() { CloneUtils.kryoClone(MAP_SIZE_1); }
@Benchmark public void hessian_size_1() { CloneUtils.hessianClone(MAP_SIZE_1); }
@Benchmark public void java_size_1() { CloneUtils.javaClone(MAP_SIZE_1); }
@Benchmark public void json_size_10() { CloneUtils.jsonClone(MAP_SIZE_10); }
@Benchmark public void kryo_size_10() { CloneUtils.kryoClone(MAP_SIZE_10); }
@Benchmark public void hessian_size_10() { CloneUtils.hessianClone(MAP_SIZE_10); }
@Benchmark public void java_size_10() { CloneUtils.javaClone(MAP_SIZE_10); }
@Benchmark public void json_size_100() { CloneUtils.jsonClone(MAP_SIZE_100); }
@Benchmark public void kryo_size_100() { CloneUtils.kryoClone(MAP_SIZE_100); }
@Benchmark public void hessian_size_100() { CloneUtils.hessianClone(MAP_SIZE_100); }
@Benchmark public void java_size_100() { CloneUtils.javaClone(MAP_SIZE_100); }
public static void main(String[] args) throws Exception { Options opt = new OptionsBuilder() .include(SerializerCmp.class.getSimpleName()) .build();
new Runner(opt).run(); } }
|