Skip to content

Commit f7341b4

Browse files
authored
Replace number formatting operations on Number
This replaces the implementations of toExponential, toFixed, and toPrecision on the Number class with new implementations that use a combination of BigDecimal and the new double formatting code.
1 parent f7ad83e commit f7341b4

10 files changed

Lines changed: 200471 additions & 924 deletions

File tree

benchmarks/src/jmh/java/org/mozilla/javascript/benchmarks/NumberFormatBenchmark.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.concurrent.TimeUnit;
44
import org.mozilla.javascript.ScriptRuntime;
5+
import org.mozilla.javascript.dtoa.DecimalFormatter;
56
import org.openjdk.jmh.annotations.Benchmark;
67
import org.openjdk.jmh.annotations.OutputTimeUnit;
78

@@ -34,4 +35,29 @@ public Object scriptRuntimeSmall() {
3435
public Object scriptRuntimeBig() {
3536
return ScriptRuntime.toString(314000000000000000000.0);
3637
}
38+
39+
@Benchmark
40+
public Object toFixedPi() {
41+
return DecimalFormatter.toFixed(Math.PI, 20);
42+
}
43+
44+
@Benchmark
45+
public Object toExponentialPi() {
46+
return DecimalFormatter.toExponential(Math.PI, 20);
47+
}
48+
49+
@Benchmark
50+
public Object toExponentialPiDefault() {
51+
return DecimalFormatter.toExponential(Math.PI, -1);
52+
}
53+
54+
@Benchmark
55+
public Object toFixedDenormal() {
56+
return DecimalFormatter.toFixed(DENORMAL, 20);
57+
}
58+
59+
@Benchmark
60+
public Object toExponentialDenormal() {
61+
return DecimalFormatter.toExponential(DENORMAL, 20);
62+
}
3763
}

0 commit comments

Comments
 (0)