mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-22 21:00:31 +00:00
fix benchmark
This commit is contained in:
parent
ff03a8eeb6
commit
515ffa092b
@ -58,6 +58,9 @@ public class Integers {
|
||||
private int[] intsSmall;
|
||||
private int[] intsBig;
|
||||
private int[] res;
|
||||
private int[] hexsTiny;
|
||||
private int[] hexsSmall;
|
||||
private int[] hexsBig;
|
||||
|
||||
@Setup
|
||||
public void setup() {
|
||||
@ -68,11 +71,18 @@ public class Integers {
|
||||
intsSmall = new int[size];
|
||||
intsBig = new int[size];
|
||||
res = new int[size];
|
||||
hexsTiny = new int[size];
|
||||
hexsSmall = new int[size];
|
||||
hexsBig = 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;
|
||||
|
||||
hexsTiny[i] = r.nextInt(0xFF);
|
||||
hexsSmall[i] = 0x100 * i + i + 0x103;
|
||||
hexsBig[i] = ((0x100 * i + i) << 24) + 0x4543 + i * 4;
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,21 +126,21 @@ public class Integers {
|
||||
|
||||
@Benchmark
|
||||
public void toHexStringTiny(Blackhole bh) {
|
||||
for (int i : intsTiny) {
|
||||
for (int i : hexsTiny) {
|
||||
bh.consume(Integer.toHexString(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void toHexStringSmall(Blackhole bh) {
|
||||
for (int i : intsSmall) {
|
||||
for (int i : hexsSmall) {
|
||||
bh.consume(Integer.toHexString(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void toHexStringBig(Blackhole bh) {
|
||||
for (int i : intsBig) {
|
||||
for (int i : hexsBig) {
|
||||
bh.consume(Integer.toHexString(i));
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,6 +54,8 @@ public class Longs {
|
||||
private String[] strings;
|
||||
private long[] longArraySmall;
|
||||
private long[] longArrayBig;
|
||||
private long[] hexsArraySmall;
|
||||
private long[] hexsArrayBig;
|
||||
|
||||
@Setup
|
||||
public void setup() {
|
||||
@ -63,10 +65,14 @@ public class Longs {
|
||||
res = new long[size];
|
||||
longArraySmall = new long[size];
|
||||
longArrayBig = new long[size];
|
||||
hexsArraySmall = new long[size];
|
||||
hexsArrayBig = new long[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
strings[i] = "" + (random.nextLong(10000) - 5000);
|
||||
longArraySmall[i] = 100L * i + i + 103L;
|
||||
longArrayBig[i] = ((100L * i + i) << 32) + 4543 + i * 4L;
|
||||
hexsArraySmall[i] = 0x100L * i + i + 0x103L;
|
||||
hexsArrayBig[i] = ((0x100L * i + i) << 32) + 0x4543 + i * 4L;
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,14 +101,14 @@ public class Longs {
|
||||
|
||||
@Benchmark
|
||||
public void toHexStringSmall(Blackhole bh) {
|
||||
for (long value : longArraySmall) {
|
||||
for (long value : hexsArraySmall) {
|
||||
bh.consume(Long.toHexString(value));
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void toHexStringBig(Blackhole bh) {
|
||||
for (long value : longArrayBig) {
|
||||
for (long value : hexsArrayBig) {
|
||||
bh.consume(Long.toHexString(value));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user