]> git.kaiwu.me - quickjs.git/commitdiff
more dtoa bench (Charlie Gordon)
authorFabrice Bellard <fabrice@bellard.org>
Sat, 22 Mar 2025 11:50:11 +0000 (12:50 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Sat, 22 Mar 2025 11:50:11 +0000 (12:50 +0100)
tests/microbench.js

index 1182c1a326a0ddccf60d413e87c5e8cc0bef22a7..4f69c40e3bc36c103d6d75a49f12cddc4af9833d 100644 (file)
@@ -1107,14 +1107,88 @@ function int_to_string(n)
     return n * 2;
 }
 
+function int_to_string(n)
+{
+    var s, r, j;
+    r = 0;
+    for(j = 0; j < n; j++) {
+        s = (j % 10) + '';
+        s = (j % 100) + '';
+        s = (j) + '';
+    }
+    return n * 3;
+}
+
+function int_toString(n)
+{
+    var s, r, j;
+    r = 0;
+    for(j = 0; j < n; j++) {
+        s = (j % 10).toString();
+        s = (j % 100).toString();
+        s = (j).toString();
+    }
+    return n * 3;
+}
+
 function float_to_string(n)
 {
-    var s, j;
+    var s, r, j;
+    r = 0;
+    for(j = 0; j < n; j++) {
+        s = (j % 10 + 0.1) + '';
+        s = (j + 0.1) + '';
+        s = (j * 12345678 + 0.1) + '';
+    }
+    return n * 3;
+}
+
+function float_toString(n)
+{
+    var s, r, j;
+    r = 0;
     for(j = 0; j < n; j++) {
+        s = (j % 10 + 0.1).toString();
         s = (j + 0.1).toString();
+        s = (j * 12345678 + 0.1).toString();
     }
-    global_res = s;
-    return n;
+    return n * 3;
+}
+
+function float_toFixed(n)
+{
+    var s, r, j;
+    r = 0;
+    for(j = 0; j < n; j++) {
+        s = (j % 10 + 0.1).toFixed(j % 16);
+        s = (j + 0.1).toFixed(j % 16);
+        s = (j * 12345678 + 0.1).toFixed(j % 16);
+    }
+    return n * 3;
+}
+
+function float_toPrecision(n)
+{
+    var s, r, j;
+    r = 0;
+    for(j = 0; j < n; j++) {
+        s = (j % 10 + 0.1).toPrecision(j % 16 + 1);
+        s = (j + 0.1).toPrecision(j % 16 + 1);
+        s = (j * 12345678 + 0.1).toPrecision(j % 16 + 1);
+    }
+    return n * 3;
+}
+
+function float_toExponential(n)
+{
+    var s, r, j;
+    r = 0;
+    for(j = 0; j < n; j++) {
+        s = (j % 10 + 0.1).toExponential(j % 16);
+        s = (j + 0.1).toExponential(j % 16);
+        s = (j * 12345678 + 0.1).toExponential(j % 16);
+    }
+    return n * 3;
 }
 
 function string_to_int(n)
@@ -1263,7 +1337,12 @@ function main(argc, argv, g)
         string_build3,
         string_build4,
         int_to_string,
+        int_toString,
         float_to_string,
+        float_toString,
+        float_toFixed,
+        float_toPrecision,
+        float_toExponential,
         string_to_int,
         string_to_float,
     ];