Skip to content

Commit f31feb8

Browse files
committed
[GR-32229] Add ArrayDuplicationBenchmark#arraysCopyOfToStringFromObjectArray.
PullRequest: graal/9523
2 parents a94f7d0 + bbae5ed commit f31feb8

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

compiler/src/org.graalvm.micro.benchmarks/src/micro/benchmarks/ArrayDuplicationBenchmark.java

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,36 +44,43 @@ public class ArrayDuplicationBenchmark extends BenchmarkBase {
4444

4545
private Object[][] testStringArray;
4646

47-
private Object[] dummy;
47+
private Object[][] testObjectArrayOfStrings;
48+
49+
private Object[] targetArray;
4850

4951
@Setup
5052
public void setup() {
5153
testObjectArray = new Object[TESTSIZE][];
5254
testStringArray = new Object[TESTSIZE][];
55+
testObjectArrayOfStrings = new Object[TESTSIZE][];
5356
for (int i = 0; i < TESTSIZE; i++) {
5457
testObjectArray[i] = new Object[20];
5558
testStringArray[i] = new String[200];
59+
testObjectArrayOfStrings[i] = new Object[20];
60+
for (int j = 0; j < testObjectArrayOfStrings[i].length; j++) {
61+
testObjectArrayOfStrings[i][j] = String.valueOf(j);
62+
}
5663
}
5764
}
5865

5966
@Setup(Level.Iteration)
6067
public void iterationSetup() {
61-
dummy = new Object[TESTSIZE * 3];
68+
targetArray = new Object[TESTSIZE * 3];
6269
}
6370

6471
@TearDown(Level.Iteration)
6572
public void iterationTearDown() {
66-
dummy = null;
73+
targetArray = null;
6774
}
6875

6976
@Benchmark
7077
@OperationsPerInvocation(TESTSIZE)
7178
public Object[] normalArraycopy() {
7279
int j = 0;
7380
for (int i = 0; i < TESTSIZE; i++) {
74-
dummy[j++] = normalArraycopy(testObjectArray[i]);
81+
targetArray[j++] = normalArraycopy(testObjectArray[i]);
7582
}
76-
return dummy;
83+
return targetArray;
7784
}
7885

7986
public Object[] normalArraycopy(Object[] cache) {
@@ -87,9 +94,9 @@ public Object[] normalArraycopy(Object[] cache) {
8794
public Object[] arraysCopyOf() {
8895
int j = 0;
8996
for (int i = 0; i < TESTSIZE; i++) {
90-
dummy[j++] = arraysCopyOf(testObjectArray[i]);
97+
targetArray[j++] = arraysCopyOf(testObjectArray[i]);
9198
}
92-
return dummy;
99+
return targetArray;
93100
}
94101

95102
public Object[] arraysCopyOf(Object[] cache) {
@@ -101,9 +108,19 @@ public Object[] arraysCopyOf(Object[] cache) {
101108
public Object[] arraysCopyOfToString() {
102109
int j = 0;
103110
for (int i = 0; i < TESTSIZE; i++) {
104-
dummy[j++] = arraysCopyOfToString(testStringArray[i]);
111+
targetArray[j++] = arraysCopyOfToString(testStringArray[i]);
112+
}
113+
return targetArray;
114+
}
115+
116+
@Benchmark
117+
@OperationsPerInvocation(TESTSIZE)
118+
public Object[] arraysCopyOfToStringFromObjectArray() {
119+
int j = 0;
120+
for (int i = 0; i < TESTSIZE; i++) {
121+
targetArray[j++] = arraysCopyOfToString(testObjectArrayOfStrings[i]);
105122
}
106-
return dummy;
123+
return targetArray;
107124
}
108125

109126
public Object[] arraysCopyOfToString(Object[] cache) {
@@ -115,9 +132,9 @@ public Object[] arraysCopyOfToString(Object[] cache) {
115132
public Object[] cloneObjectArray() {
116133
int j = 0;
117134
for (int i = 0; i < TESTSIZE; i++) {
118-
dummy[j++] = arraysClone(testObjectArray[i]);
135+
targetArray[j++] = arraysClone(testObjectArray[i]);
119136
}
120-
return dummy;
137+
return targetArray;
121138
}
122139

123140
@SuppressWarnings("cast")

0 commit comments

Comments
 (0)