Skip to content

Commit 2be9a81

Browse files
committed
Move data creation to a single method
1 parent 7bfb05b commit 2be9a81

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/test/java/com/github/packageurl/internal/StringUtilBenchmark.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,14 @@ public class StringUtilBenchmark {
7272

7373
@Setup
7474
public void setup() {
75-
createDecodedData();
76-
createEncodedData();
75+
createData();
7776
}
7877

79-
private void createDecodedData() {
78+
private void createData() {
8079
decodedData = new String[DATA_COUNT];
81-
for (int i = 0; i < DATA_COUNT; i++) {
80+
for (int i = 0; i < decodedData.length; i++) {
8281
char[] chars = new char[DECODED_LENGTH];
83-
for (int j = 0; j < DECODED_LENGTH; j++) {
82+
for (int j = 0; j < chars.length; j++) {
8483
if (RANDOM.nextDouble() < nonAsciiProb) {
8584
chars[j] = (char) (Byte.MAX_VALUE + 1 + RANDOM.nextInt(Short.MAX_VALUE - Byte.MAX_VALUE - 1));
8685
} else {
@@ -89,9 +88,7 @@ private void createDecodedData() {
8988
}
9089
decodedData[i] = new String(chars);
9190
}
92-
}
9391

94-
private void createEncodedData() {
9592
encodedData = new String[decodedData.length];
9693
for (int i = 0; i < encodedData.length; i++) {
9794
encodedData[i] = StringUtil.percentEncode(decodedData[i]);

0 commit comments

Comments
 (0)