mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8267844: Replace Integer/Long.valueOf() with Integer/Long.parse*() where applicable
Reviewed-by: redestad
This commit is contained in:
parent
d38b31438d
commit
b29fbad940
6 changed files with 31 additions and 13 deletions
|
@ -35,6 +35,7 @@ import org.openjdk.jmh.annotations.State;
|
|||
import org.openjdk.jmh.annotations.Warmup;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
|
@ -48,16 +49,20 @@ public class Longs {
|
|||
@Param("500")
|
||||
private int size;
|
||||
|
||||
private String[] strings;
|
||||
private long[] longArraySmall;
|
||||
private long[] longArrayBig;
|
||||
|
||||
@Setup
|
||||
public void setup() {
|
||||
var random = ThreadLocalRandom.current();
|
||||
strings = new String[size];
|
||||
longArraySmall = new long[size];
|
||||
longArrayBig = 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 * 4;
|
||||
longArrayBig[i] = ((100L * i + i) << 32) + 4543 + i * 4L;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,6 +74,13 @@ public class Longs {
|
|||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void decode(Blackhole bh) {
|
||||
for (String s : strings) {
|
||||
bh.consume(Long.decode(s));
|
||||
}
|
||||
}
|
||||
|
||||
/** Performs toString on large values, around 10 digits. */
|
||||
@Benchmark
|
||||
public void toStringBig(Blackhole bh) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue