Skip to content

Commit

Permalink
Setting JVM opts
Browse files Browse the repository at this point in the history
  • Loading branch information
Suszyński Krzysztof committed Mar 30, 2016
1 parent 24d4bf8 commit b6e1f7b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 41 deletions.
47 changes: 6 additions & 41 deletions src/test/java/pl/wavesoftware/eid/exceptions/EidIT.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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()
Expand All @@ -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);
Expand All @@ -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"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b6e1f7b

Please sign in to comment.