diff --git a/src/test/java/pl/wavesoftware/eid/exceptions/EidIT.java b/src/test/java/pl/wavesoftware/eid/exceptions/EidIT.java index a3f93a5..4a4f502 100644 --- a/src/test/java/pl/wavesoftware/eid/exceptions/EidIT.java +++ b/src/test/java/pl/wavesoftware/eid/exceptions/EidIT.java @@ -1,14 +1,10 @@ package pl.wavesoftware.eid.exceptions; -import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; import org.junit.rules.RuleChain; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Mode; -import org.openjdk.jmh.annotations.Scope; -import org.openjdk.jmh.annotations.Setup; -import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.infra.Blackhole; import org.openjdk.jmh.results.RunResult; import org.openjdk.jmh.runner.Runner; @@ -20,7 +16,6 @@ import pl.wavesoftware.testing.JavaAgentSkip; import pl.wavesoftware.testing.JmhCleaner; -import java.text.NumberFormat; import java.util.Collection; import java.util.Date; import java.util.concurrent.TimeUnit; @@ -43,26 +38,6 @@ public class EidIT { .outerRule(new JmhCleaner(EidIT.class)) .around(JavaAgentSkip.ifActive()); - @Before - public void before() { - printMemory(); - } - - public static void printMemory() { - Runtime runtime = Runtime.getRuntime(); - - NumberFormat format = NumberFormat.getInstance(); - - long maxMemory = runtime.maxMemory(); - long allocatedMemory = runtime.totalMemory(); - long freeMemory = runtime.freeMemory(); - - LOG.info("free memory: {} KiB", format.format(freeMemory / 1024)); - LOG.info("allocated memory: {} KiB", format.format(allocatedMemory / 1024)); - LOG.info("max memory: {} KiB", format.format(maxMemory / 1024)); - LOG.info("total free memory: {} KiB", format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024)); - } - @Test public void doBenckmarking() throws Exception { Options opt = new OptionsBuilder() @@ -78,6 +53,7 @@ public void doBenckmarking() throws Exception { .forks(1) .shouldFailOnError(true) .shouldDoGC(true) + .jvmArgs("-server", "-Xms256m", "-Xmx256m", "-XX:PermSize=128m", "-XX:MaxPermSize=128m", "-XX:+UseParallelGC") .build(); Runner runner = new Runner(opt); @@ -98,35 +74,24 @@ public void doBenckmarking() throws Exception { double eidTimes = eidScore / controlScore; - LOG.info(String.format("Control sample method time per operation: %.2f µsec", controlScore)); - LOG.info(String.format("#eid() method time per operation: %.2f µsec", eidScore)); + LOG.info(String.format("Control sample method time per operation: %.2f ops / µsec", controlScore)); + LOG.info(String.format("#eid() method time per operation: %.2f ops / µsec", eidScore)); LOG.info(String.format("%s and is %.2f%%", eidTitle, eidTimes * PERCENT)); assertThat(eidTimes).as(eidTitle).isGreaterThanOrEqualTo(SPEED_THRESHOLD); } - @State(Scope.Benchmark) - public static class MemoryState { - private String eid; - - @Setup - public void setup() { - printMemory(); - this.eid = "20160330:124244"; - } - } - @Benchmark - public void control(MemoryState state, Blackhole bh) { + public void control(Blackhole bh) { for (int i = 0; i < OPERATIONS; i++) { bh.consume(new Date()); } } @Benchmark - public void eid(MemoryState state, Blackhole bh) { + public void eid(Blackhole bh) { for (int i = 0; i < OPERATIONS; i++) { - bh.consume(new Eid(state.eid)); + bh.consume(new Eid("20160330:144947")); } } diff --git a/src/test/java/pl/wavesoftware/eid/utils/EidPreconditionsIT.java b/src/test/java/pl/wavesoftware/eid/utils/EidPreconditionsIT.java index a5b38fe..aa268f0 100644 --- a/src/test/java/pl/wavesoftware/eid/utils/EidPreconditionsIT.java +++ b/src/test/java/pl/wavesoftware/eid/utils/EidPreconditionsIT.java @@ -62,6 +62,7 @@ public void doBenchmarking() throws RunnerException { .forks(1) .shouldFailOnError(true) .shouldDoGC(true) + .jvmArgs("-server", "-Xms256m", "-Xmx256m", "-XX:PermSize=128m", "-XX:MaxPermSize=128m", "-XX:+UseParallelGC") .build(); Runner runner = new Runner(opt);