Skip to content

Commit 0f1efb9

Browse files
committed
Performance test
1 parent 325d881 commit 0f1efb9

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@
9292
<version>1.11.3</version>
9393
<scope>test</scope>
9494
</dependency>
95+
<dependency>
96+
<groupId>org.slf4j</groupId>
97+
<artifactId>slf4j-simple</artifactId>
98+
<version>1.7.13</version>
99+
<scope>test</scope>
100+
</dependency>
95101

96102
</dependencies>
97103

src/main/java/pl/wavesoftware/eid/exceptions/Eid.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ public class Eid implements Serializable {
6464

6565
private final Future<String> futureUniqueId;
6666

67-
private final Future<String> repr;
68-
6967
/**
7068
* Constructor
7169
*
@@ -81,7 +79,6 @@ protected String produce() {
8179
};
8280
this.id = id;
8381
this.ref = ref == null ? "" : ref;
84-
repr = new ToStringRepr();
8582
}
8683

8784
/**
@@ -185,7 +182,10 @@ public String makeLogMessage(@Nonnull String logMessageFormat, @Nonnull Object..
185182

186183
@Override
187184
public String toString() {
188-
return repr.get();
185+
if ("".equals(ref)) {
186+
return String.format(format, id, futureUniqueId.get());
187+
}
188+
return String.format(refFormat, id, ref, futureUniqueId.get());
189189
}
190190

191191
/**
@@ -262,17 +262,6 @@ public T get() {
262262
}
263263
}
264264

265-
private class ToStringRepr extends StdFuture<String> {
266-
267-
@Override
268-
protected String produce() {
269-
if ("".equals(ref)) {
270-
return String.format(format, id, futureUniqueId.get());
271-
}
272-
return String.format(refFormat, id, ref, futureUniqueId.get());
273-
}
274-
}
275-
276265
private static final class StdUniqIdGenerator implements UniqIdGenerator {
277266

278267
private static final int BASE36 = 36;

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.openjdk.jmh.runner.options.Options;
1111
import org.openjdk.jmh.runner.options.OptionsBuilder;
1212
import org.openjdk.jmh.runner.options.TimeValue;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
1315

1416
import java.util.Collection;
1517
import java.util.Date;
@@ -24,6 +26,9 @@
2426
public class EidIT {
2527

2628
private static final int OPERATIONS = 1000;
29+
private static final Logger LOG = LoggerFactory.getLogger(EidIT.class);
30+
private static final double SPEED_THRESHOLD = 0.75d;
31+
public static final int PERCENT = 100;
2732

2833
@Test
2934
public void doBenckmarking() throws Exception {
@@ -45,6 +50,26 @@ public void doBenckmarking() throws Exception {
4550
Runner runner = new Runner(opt);
4651
Collection<RunResult> results = runner.run();
4752
assertThat(results).hasSize(2);
53+
54+
RunResult control = getRunResultByName(results, "control");
55+
RunResult eid = getRunResultByName(results, "eid");
56+
assertThat(control).isNotNull();
57+
assertThat(eid).isNotNull();
58+
59+
double controlScore = control.getAggregatedResult().getPrimaryResult().getScore();
60+
double eidScore = eid.getAggregatedResult().getPrimaryResult().getScore();
61+
62+
String title = "method speed quotient to the control sample";
63+
String eidTitle = String.format("%s %s should be at least %.2f%%", "#exhibit()",
64+
title, SPEED_THRESHOLD * PERCENT);
65+
66+
double eidTimes = eidScore / controlScore;
67+
68+
LOG.info(String.format("Control sample method time per operation: %.2f µsec", controlScore));
69+
LOG.info(String.format("#eid() method time per operation: %.2f µsec", eidScore));
70+
LOG.info(String.format("%s and is %.2f%%", eidTitle, eidTimes * PERCENT));
71+
72+
assertThat(eidTimes).as(eidTitle).isGreaterThanOrEqualTo(SPEED_THRESHOLD);
4873
}
4974

5075
@Benchmark
@@ -60,4 +85,14 @@ public void eid(Blackhole bh) {
6085
bh.consume(new Eid("20160324:223837"));
6186
}
6287
}
88+
89+
private static RunResult getRunResultByName(Collection<RunResult> results, String name) {
90+
String fullName = String.format("%s.%s", EidIT.class.getName(), name);
91+
for (RunResult result : results) {
92+
if (result.getParams().getBenchmark().equals(fullName)) {
93+
return result;
94+
}
95+
}
96+
throw new EidRuntimeException("20160324:225412", "Invalid name: " + name);
97+
}
6398
}

0 commit comments

Comments
 (0)