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
| package com.ap.core.pipeline.shared.io.logger;
import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder;
@BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MICROSECONDS) @State(Scope.Benchmark) @Slf4j public class LoggerTest {
@Param({"100", "1000", "10000", "100000"}) public int setSize;
@Benchmark public void logoutputWithConcatnationShort() { for (int i = 0; i < setSize; i++) { log.info("abc askdfj aldfj " + "afdakl"); } }
@Benchmark public void logoutputWithConcatnationMedium() { for (int i = 0; i < setSize; i++) { log.info("abc askdfj aldfj " + "afdakl " + " asdfa " + " kadjfka d " + " alsdjflas"); } }
@Benchmark public void logoutputWithConcatnationLong() { for (int i = 0; i < setSize; i++) { log.info( "abc askdfj aldfj " + "afdakl " + " asdfa " + " kadjfka d " + " alsdjflas " + " asfas;a " + " akdjfakj " + " ladjla kdfaks dfla " + " laksdjfklas ljaf;", " asdfjla fldsj;" ); } }
@Benchmark public void logoutputWithInterpolationShort() { for (int i = 0; i < setSize; i++) { log.info("{} {}", "abc askdfj aldfj ", "afdakl"); } }
@Benchmark public void logoutputWithInterpolationMedium() { for (int i = 0; i < setSize; i++) { log.info("{} {} {} {} {}", "abc askdfj aldfj ", "afdakl ", " asdfa ", " kadjfka d ", " alsdjflas"); } }
@Benchmark public void logoutputWithInterpolationLong() { for (int i = 0; i < setSize; i++) { log.info( "{} {} {} {} {} {} {} {} {} {}" ,"abc askdfj aldfj " , "afdakl " , " asdfa " , " kadjfka d " , " alsdjflas " , " asfas;a " , " akdjfakj " , " ladjla kdfaks dfla " , " laksdjfklas ljaf; ", " asdfjla fldsj;" ); } }
public static void main(String... args) throws RunnerException { Options opts = new OptionsBuilder() .include(".*") .warmupIterations(1) .measurementIterations(2) .jvmArgs("-Xms2g", "-Xmx2g") .shouldDoGC(true) .forks(1) .build();
new Runner(opts).run(); }
}
|