8278831: Use table lookup for the last two bytes in Integer.getChars

Reviewed-by: jlaskey, rriggs
This commit is contained in:
Claes Redestad 2022-01-17 11:01:55 +00:00
parent 431bd9a66d
commit 71ca85f5a6
4 changed files with 26 additions and 31 deletions

View file

@ -53,17 +53,20 @@ public class Integers {
private int size;
private String[] strings;
private int[] intsTiny;
private int[] intsSmall;
private int[] intsBig;
@Setup
public void setup() {
Random r = new Random(0);
strings = new String[size];
Random r = new Random(0);
strings = new String[size];
intsTiny = new int[size];
intsSmall = new int[size];
intsBig = new int[size];
intsBig = new int[size];
for (int i = 0; i < size; i++) {
strings[i] = "" + (r.nextInt(10000) - (5000));
intsTiny[i] = r.nextInt(99);
intsSmall[i] = 100 * i + i + 103;
intsBig[i] = ((100 * i + i) << 24) + 4543 + i * 4;
}
@ -91,6 +94,14 @@ public class Integers {
}
}
/** Performs toString on very small values, just one or two digits. */
@Benchmark
public void toStringTiny(Blackhole bh) {
for (int i : intsTiny) {
bh.consume(Integer.toString(i));
}
}
/** Performs toString on large values, roughly 10 digits. */
@Benchmark
public void toStringBig(Blackhole bh) {