Skip to content

Commit b6e1f7b

Browse files
author
Suszyński Krzysztof
committed
Setting JVM opts
1 parent 24d4bf8 commit b6e1f7b

File tree

2 files changed

+7
-41
lines changed

2 files changed

+7
-41
lines changed

src/test/java/pl/wavesoftware/eid/exceptions/EidIT.java

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
package pl.wavesoftware.eid.exceptions;
22

3-
import org.junit.Before;
43
import org.junit.ClassRule;
54
import org.junit.Test;
65
import org.junit.rules.RuleChain;
76
import org.openjdk.jmh.annotations.Benchmark;
87
import org.openjdk.jmh.annotations.Mode;
9-
import org.openjdk.jmh.annotations.Scope;
10-
import org.openjdk.jmh.annotations.Setup;
11-
import org.openjdk.jmh.annotations.State;
128
import org.openjdk.jmh.infra.Blackhole;
139
import org.openjdk.jmh.results.RunResult;
1410
import org.openjdk.jmh.runner.Runner;
@@ -20,7 +16,6 @@
2016
import pl.wavesoftware.testing.JavaAgentSkip;
2117
import pl.wavesoftware.testing.JmhCleaner;
2218

23-
import java.text.NumberFormat;
2419
import java.util.Collection;
2520
import java.util.Date;
2621
import java.util.concurrent.TimeUnit;
@@ -43,26 +38,6 @@ public class EidIT {
4338
.outerRule(new JmhCleaner(EidIT.class))
4439
.around(JavaAgentSkip.ifActive());
4540

46-
@Before
47-
public void before() {
48-
printMemory();
49-
}
50-
51-
public static void printMemory() {
52-
Runtime runtime = Runtime.getRuntime();
53-
54-
NumberFormat format = NumberFormat.getInstance();
55-
56-
long maxMemory = runtime.maxMemory();
57-
long allocatedMemory = runtime.totalMemory();
58-
long freeMemory = runtime.freeMemory();
59-
60-
LOG.info("free memory: {} KiB", format.format(freeMemory / 1024));
61-
LOG.info("allocated memory: {} KiB", format.format(allocatedMemory / 1024));
62-
LOG.info("max memory: {} KiB", format.format(maxMemory / 1024));
63-
LOG.info("total free memory: {} KiB", format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024));
64-
}
65-
6641
@Test
6742
public void doBenckmarking() throws Exception {
6843
Options opt = new OptionsBuilder()
@@ -78,6 +53,7 @@ public void doBenckmarking() throws Exception {
7853
.forks(1)
7954
.shouldFailOnError(true)
8055
.shouldDoGC(true)
56+
.jvmArgs("-server", "-Xms256m", "-Xmx256m", "-XX:PermSize=128m", "-XX:MaxPermSize=128m", "-XX:+UseParallelGC")
8157
.build();
8258

8359
Runner runner = new Runner(opt);
@@ -98,35 +74,24 @@ public void doBenckmarking() throws Exception {
9874

9975
double eidTimes = eidScore / controlScore;
10076

101-
LOG.info(String.format("Control sample method time per operation: %.2f µsec", controlScore));
102-
LOG.info(String.format("#eid() method time per operation: %.2f µsec", eidScore));
77+
LOG.info(String.format("Control sample method time per operation: %.2f ops / µsec", controlScore));
78+
LOG.info(String.format("#eid() method time per operation: %.2f ops / µsec", eidScore));
10379
LOG.info(String.format("%s and is %.2f%%", eidTitle, eidTimes * PERCENT));
10480

10581
assertThat(eidTimes).as(eidTitle).isGreaterThanOrEqualTo(SPEED_THRESHOLD);
10682
}
10783

108-
@State(Scope.Benchmark)
109-
public static class MemoryState {
110-
private String eid;
111-
112-
@Setup
113-
public void setup() {
114-
printMemory();
115-
this.eid = "20160330:124244";
116-
}
117-
}
118-
11984
@Benchmark
120-
public void control(MemoryState state, Blackhole bh) {
85+
public void control(Blackhole bh) {
12186
for (int i = 0; i < OPERATIONS; i++) {
12287
bh.consume(new Date());
12388
}
12489
}
12590

12691
@Benchmark
127-
public void eid(MemoryState state, Blackhole bh) {
92+
public void eid(Blackhole bh) {
12893
for (int i = 0; i < OPERATIONS; i++) {
129-
bh.consume(new Eid(state.eid));
94+
bh.consume(new Eid("20160330:144947"));
13095
}
13196
}
13297

src/test/java/pl/wavesoftware/eid/utils/EidPreconditionsIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public void doBenchmarking() throws RunnerException {
6262
.forks(1)
6363
.shouldFailOnError(true)
6464
.shouldDoGC(true)
65+
.jvmArgs("-server", "-Xms256m", "-Xmx256m", "-XX:PermSize=128m", "-XX:MaxPermSize=128m", "-XX:+UseParallelGC")
6566
.build();
6667

6768
Runner runner = new Runner(opt);

0 commit comments

Comments
 (0)