Skip to content

Instantly share code, notes, and snippets.

@JosePaumard
Created October 14, 2024 07:30
Show Gist options
  • Select an option

  • Save JosePaumard/0c75aa532424460201fae838f9c05026 to your computer and use it in GitHub Desktop.

Select an option

Save JosePaumard/0c75aa532424460201fae838f9c05026 to your computer and use it in GitHub Desktop.
package org.paumard.equals;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@Warmup(iterations = 5, time = 400, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 400, timeUnit = TimeUnit.MILLISECONDS)
@Fork(value = 3)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
public class BenchJEPCafe21 {
@Param({"400"})
private int SIZE;
@Param({"100", "10", "4", "2", "1"})
private int NUMBER_OF_GLITCHES;
@Param({"InstanceOf", "Equals InstanceOf",
"Record", "Pattern Matching", "PM with equals",
"IntelliJ", "Eclipse", "Commons Lang", "Guava"})
private String equalsMethod;
@Param({"SameObject Glitch",
"EqualObject Glitch",
"SameType_AllDifferent Same Glitch",
"SameType_AllDifferent Equal Glitch",
"DifferentType Same Glitch",
"DifferentType Equal Glitch"})
private String comparison;
private List<Object> currentObjects;
private Object currentPoint;
record PointV0(int x, int y) {
public boolean equals(Object o) {
if (o instanceof PointV0) {
PointV0 point = (PointV0) o;
return point.x == this.x && point.y == this.y;
}
return false;
}
}
record PointV1(int x, int y) {
public boolean equals(Object o) {
if (this == o) return true;
if (o instanceof PointV1) {
PointV1 point = (PointV1) o;
return point.x == this.x && point.y == this.y;
}
return false;
}
}
record PointV2(int x, int y) {
@Override
public boolean equals(Object o) { // default IntelliJ
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PointV2 point = (PointV2) o;
if (x != point.x) return false;
return y == point.y;
}
}
record PointV3(int x, int y) { // Eclipse Default
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if (getClass() != o.getClass()) return false;
PointV3 other = (PointV3) o;
if (x != other.x) return false;
if (y != other.y) return false;
return true;
}
}
record PointV4(int x, int y) { // Commons Lang 3
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PointV4 point = (PointV4) o;
return new EqualsBuilder().append(x, point.x).append(y, point.y).isEquals();
}
}
record PointV5(int x, int y) { // Guava
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PointV5 point = (PointV5) o;
return x == point.x && y == point.y;
}
}
record PointV6(int x, int y) {
}
record PointV7(int x, int y) {
@Override
public boolean equals(Object o) {
return o instanceof PointV7(int x, int y) && x == this.x && y == this.y;
}
}
record PointV8(int x, int y) {
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
} else {
return o instanceof PointV8(int x, int y) && x == this.x && y == this.y;
}
}
}
private final PointV0 pv0 = new PointV0(0, 0);
private final PointV1 pv1 = new PointV1(0, 0);
private final PointV2 pv2 = new PointV2(0, 0);
private final PointV3 pv3 = new PointV3(0, 0);
private final PointV4 pv4 = new PointV4(0, 0);
private final PointV5 pv5 = new PointV5(0, 0);
private final PointV6 pv6 = new PointV6(0, 0);
private final PointV7 pv7 = new PointV7(0, 0);
private final PointV8 pv8 = new PointV8(0, 0);
private final PointV0 pv0Diff = new PointV0(0, 1);
private final PointV1 pv1Diff = new PointV1(0, 1);
private final PointV2 pv2Diff = new PointV2(0, 1);
private final PointV3 pv3Diff = new PointV3(0, 1);
private final PointV4 pv4Diff = new PointV4(0, 1);
private final PointV5 pv5Diff = new PointV5(0, 1);
private final PointV6 pv6Diff = new PointV6(0, 1);
private final PointV7 pv7Diff = new PointV7(0, 1);
private final PointV8 pv8Diff = new PointV8(0, 1);
@Setup
public void init() {
switch(equalsMethod) {
// "InstanceOf", "Equals InstanceOf", "Record",
// "IntelliJ", "Eclipse", "Commons Lang", "Guava",
// "Pattern Matching", "PM with equals"
case "InstanceOf" -> {
currentPoint = pv0;
switch (comparison) {
// "SameObject", "EqualObject", "SameType_AllDifferent", "DifferentType"
case "SameObject" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> pv0)
.collect(Collectors.toList());
case "SameObject Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> pv0)
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv0Diff);
}
}
case "EqualObject" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV0(pv0.x, pv0.y))
.collect(Collectors.toList());
case "EqualObject Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV0(pv0.x, pv0.y))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv0Diff);
}
}
case "SameType_AllDifferent" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV0(index, index))
.collect(Collectors.toList());
case "SameType_AllDifferent Same Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV0(index, index))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv0);
}
}
case "SameType_AllDifferent Equal Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV0(index, index))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, new PointV0(pv0.x, pv0.y));
}
}
case "DifferentType" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
case "DifferentType Same Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv0);
}
}
case "DifferentType Equal Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, new PointV0(pv0.x, pv0.y));
}
}
}
}
case "Equals InstanceOf" -> {
currentPoint = pv1;
switch (comparison) {
// "SameObject", "EqualObject", "SameType_AllDifferent", "DifferentType"
case "SameObject" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> pv1)
.collect(Collectors.toList());
case "SameObject Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> pv1)
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv1Diff);
}
}
case "EqualObject" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV1(pv1.x, pv1.y))
.collect(Collectors.toList());
case "EqualObject Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV1(pv1.x, pv1.y))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv1Diff);
}
}
case "SameType_AllDifferent" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV1(index, index))
.collect(Collectors.toList());
case "SameType_AllDifferent Same Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV1(index, index))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv1);
}
}
case "SameType_AllDifferent Equal Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV1(index, index))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, new PointV1(pv1.x, pv1.y));
}
}
case "DifferentType" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
case "DifferentType Same Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv1);
}
}
case "DifferentType Equal Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, new PointV1(pv1.x, pv1.y));
}
}
}
}
case "IntelliJ" -> {
currentPoint = pv2;
switch (comparison) {
case "SameObject" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> pv2)
.collect(Collectors.toList());
case "SameObject Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> pv2)
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv2Diff);
}
}
case "EqualObject" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV2(pv2.x, pv2.y))
.collect(Collectors.toList());
case "EqualObject Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV2(pv2.x, pv2.y))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv2Diff);
}
}
case "SameType_AllDifferent" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV2(index, index))
.collect(Collectors.toList());
case "SameType_AllDifferent Same Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV2(index, index))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv2);
}
}
case "SameType_AllDifferent Equal Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV2(index, index))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, new PointV2(pv2.x, pv2.y));
}
}
case "DifferentType" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
case "DifferentType Same Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv2);
}
}
case "DifferentType Equal Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, new PointV2(pv2.x, pv2.y));
}
}
}
}
case "Eclipse" -> {
currentPoint = pv3;
switch (comparison) {
case "SameObject" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> pv3)
.collect(Collectors.toList());
case "SameObject Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> pv3)
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv3Diff);
}
}
case "EqualObject" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV3(pv3.x, pv3.y))
.collect(Collectors.toList());
case "EqualObject Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV3(pv3.x, pv3.y))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv3Diff);
}
}
case "SameType_AllDifferent" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV3(index, index))
.collect(Collectors.toList());
case "SameType_AllDifferent Same Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV3(index, index))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv3);
}
}
case "SameType_AllDifferent Equal Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV3(index, index))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, new PointV3(pv3.x, pv3.y));
}
}
case "DifferentType" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
case "DifferentType Same Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv3);
}
}
case "DifferentType Equal Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, new PointV3(pv3.x, pv3.y));
}
}
}
}
case "Commons Lang" -> {
currentPoint = pv4;
switch (comparison) {
case "SameObject" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> pv4)
.collect(Collectors.toList());
case "SameObject Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> pv4)
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv4Diff);
}
}
case "EqualObject" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV4(pv4.x, pv4.y))
.collect(Collectors.toList());
case "EqualObject Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV4(pv4.x, pv4.y))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv4Diff);
}
}
case "SameType_AllDifferent" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV4(index, index))
.collect(Collectors.toList());
case "SameType_AllDifferent Same Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV4(index, index))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv4);
}
}
case "SameType_AllDifferent Equal Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV4(index, index))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, new PointV4(pv4.x, pv4.y));
}
}
case "DifferentType" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
case "DifferentType Same Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv4);
}
}
case "DifferentType Equal Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, new PointV4(pv4.x, pv4.y));
}
}
}
}
case "Guava" -> {
currentPoint = pv5;
switch (comparison) {
case "SameObject" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> pv5)
.collect(Collectors.toList());
case "SameObject Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> pv5)
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv5Diff);
}
}
case "EqualObject" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV5(pv5.x, pv5.y))
.collect(Collectors.toList());
case "EqualObject Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV5(pv5.x, pv5.y))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv5Diff);
}
}
case "SameType_AllDifferent" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV5(index, index))
.collect(Collectors.toList());
case "SameType_AllDifferent Same Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV5(index, index))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv5);
}
}
case "SameType_AllDifferent Equal Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV5(index, index))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, new PointV5(pv5.x, pv5.y));
}
}
case "DifferentType" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
case "DifferentType Same Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv5);
}
}
case "DifferentType Equal Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, new PointV5(pv5.x, pv5.y));
}
}
}
}
case "Record" -> {
currentPoint = pv6;
switch (comparison) {
case "SameObject" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> pv6)
.collect(Collectors.toList());
case "SameObject Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> pv6)
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv6Diff);
}
}
case "EqualObject" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV6(pv6.x, pv6.y))
.collect(Collectors.toList());
case "EqualObject Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV6(pv6.x, pv6.y))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv6Diff);
}
}
case "SameType_AllDifferent" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV6(index, index))
.collect(Collectors.toList());
case "SameType_AllDifferent Same Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV6(index, index))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv6);
}
}
case "SameType_AllDifferent Equal Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV6(index, index))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, new PointV6(pv6.x, pv6.y));
}
}
case "DifferentType" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
case "DifferentType Same Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv6);
}
}
case "DifferentType Equal Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, new PointV6(pv6.x, pv6.y));
}
}
}
}
case "Pattern Matching" -> {
currentPoint = pv7;
switch (comparison) {
// "SameObject", "EqualObject", "SameType_AllDifferent", "DifferentType"
case "SameObject" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> pv7)
.collect(Collectors.toList());
case "SameObject Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> pv7)
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv7Diff);
}
}
case "EqualObject" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV7(pv7.x, pv7.y))
.collect(Collectors.toList());
case "EqualObject Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV7(pv7.x, pv7.y))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv7Diff);
}
}
case "SameType_AllDifferent" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV7(index, index))
.collect(Collectors.toList());
case "SameType_AllDifferent Same Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV7(index, index))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv7);
}
}
case "SameType_AllDifferent Equal Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV7(index, index))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, new PointV7(pv7.x, pv7.y));
}
}
case "DifferentType" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
case "DifferentType Same Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv7);
}
}
case "DifferentType Equal Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, new PointV7(pv7.x, pv7.y));
}
}
}
}
case "PM with equals" -> {
currentPoint = pv8;
switch (comparison) {
case "SameObject" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> pv8)
.collect(Collectors.toList());
case "SameObject Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> pv8)
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv8Diff);
}
}
case "EqualObject" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV8(pv8.x, pv8.y))
.collect(Collectors.toList());
case "EqualObject Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV8(pv8.x, pv8.y))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv8Diff);
}
}
case "SameType_AllDifferent" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV8(index, index))
.collect(Collectors.toList());
case "SameType_AllDifferent Same Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV8(index, index))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv8);
}
}
case "SameType_AllDifferent Equal Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new PointV8(index, index))
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, new PointV8(pv8.x, pv8.y));
}
}
case "DifferentType" ->
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
case "DifferentType Same Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, pv8);
}
}
case "DifferentType Equal Glitch" -> {
currentObjects = IntStream.range(1, SIZE + 1).mapToObj(index -> new Object())
.collect(Collectors.toList());
for (int index = SIZE / (NUMBER_OF_GLITCHES + 1); index < SIZE;
index += SIZE / (NUMBER_OF_GLITCHES + 1)) {
currentObjects.set(index, new PointV8(pv8.x, pv8.y));
}
}
}
}
}
}
@Benchmark
public void bench(Blackhole blackhole) {
for (var p : currentObjects) {
boolean equal = currentPoint.equals(p);
blackhole.consume(equal);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment