-
Bug
-
Resolution: Fixed
-
P4
-
17, 21, 22, 23
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8335321 | 21.0.5 | Jie Fu | P4 | Resolved | Fixed | b01 |
Create behalf on lingjun.cg@alibaba-inc.com
Run the following benchmark in Linux with 8C32G, it shows poor performance of the new DecimalFormat() when compared to jdk11.
```
@BenchmarkMode(Mode.AverageTime)
@Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@State(Scope.Thread)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public class JmhDecimalFormat {
@Setup(Level.Trial)
public void setup() {
}
@Benchmark
public void testNewOnly() throws InterruptedException {
new DecimalFormat("#0.00000");
}
}
```
the result with jdk 11:
Benchmark Mode Cnt Score Error Units
JmhDecimalFormat.testNewOnly avgt 50 248.300 ? 5.158 ns/op
the result with current jdk:
Benchmark Mode Cnt Score Error Units
JmhDecimalFormat.testNewOnly avgt 50 303.381 ? 5.252 ns/op
When run the other test case to get the flame graph:
```
import java.text.DecimalFormat;
public class DecimalTest {
private static long start;
private static long end;
public static void main(String[] args) {
start = System.currentTimeMillis();
int count = Integer.parseInt(args[0]);
DecimalFormat format;
for(int i = 0 ; i < count; i++) {
format = new DecimalFormat("#0.00000");
}
end = System.currentTimeMillis();
System.out.println("Cost " + (end-start) +" ms");
}
}
```
Compare the flame graph between JDK 11 and JDK 21, it shows "java/util/stream/IntPipeline.findFirst"
task extra 15% CPU time.
Run the following benchmark in Linux with 8C32G, it shows poor performance of the new DecimalFormat() when compared to jdk11.
```
@BenchmarkMode(Mode.AverageTime)
@Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@State(Scope.Thread)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public class JmhDecimalFormat {
@Setup(Level.Trial)
public void setup() {
}
@Benchmark
public void testNewOnly() throws InterruptedException {
new DecimalFormat("#0.00000");
}
}
```
the result with jdk 11:
Benchmark Mode Cnt Score Error Units
JmhDecimalFormat.testNewOnly avgt 50 248.300 ? 5.158 ns/op
the result with current jdk:
Benchmark Mode Cnt Score Error Units
JmhDecimalFormat.testNewOnly avgt 50 303.381 ? 5.252 ns/op
When run the other test case to get the flame graph:
```
import java.text.DecimalFormat;
public class DecimalTest {
private static long start;
private static long end;
public static void main(String[] args) {
start = System.currentTimeMillis();
int count = Integer.parseInt(args[0]);
DecimalFormat format;
for(int i = 0 ; i < count; i++) {
format = new DecimalFormat("#0.00000");
}
end = System.currentTimeMillis();
System.out.println("Cost " + (end-start) +" ms");
}
}
```
Compare the flame graph between JDK 11 and JDK 21, it shows "java/util/stream/IntPipeline.findFirst"
task extra 15% CPU time.