Skip to content

Commit 006e58a

Browse files
committed
fix: benchmark by mixing in more characters that need encoding
1 parent 8f17eee commit 006e58a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ public class StringUtilBenchmark {
5656

5757
private static final int DATA_COUNT = 1000;
5858
private static final int DECODED_LENGTH = 256;
59-
private static final byte[] UNRESERVED =
60-
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~".getBytes(StandardCharsets.US_ASCII);
59+
private static final char[] UNRESERVED =
60+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~".toCharArray();
61+
private static final char[] RESERVED = " ?&=+%#@!*()[]{}|\\:;,/<>'\"".toCharArray();
62+
6163

6264
@Param({"0", "0.1", "0.5"})
6365
private double nonAsciiProb;
@@ -71,10 +73,13 @@ private String[] createDecodedData() {
7173
for (int i = 0; i < DATA_COUNT; i++) {
7274
char[] chars = new char[DECODED_LENGTH];
7375
for (int j = 0; j < DECODED_LENGTH; j++) {
74-
if (random.nextDouble() < nonAsciiProb) {
76+
double r = random.nextDouble();
77+
if (r < nonAsciiProb) {
7578
chars[j] = (char) (Byte.MAX_VALUE + 1 + random.nextInt(Short.MAX_VALUE - Byte.MAX_VALUE - 1));
79+
} else if (r < nonAsciiProb + 0.2) {
80+
chars[j] = RESERVED[random.nextInt(RESERVED.length)];
7681
} else {
77-
chars[j] = (char) UNRESERVED[random.nextInt(UNRESERVED.length)];
82+
chars[j] = UNRESERVED[random.nextInt(UNRESERVED.length)];
7883
}
7984
}
8085
decodedData[i] = new String(chars);

0 commit comments

Comments
 (0)