]> git.kaiwu.me - quickjs.git/commitdiff
fixed hash_map_resize() - added Map/WeakMap in microbench
authorFabrice Bellard <fabrice@bellard.org>
Sat, 22 Mar 2025 09:54:21 +0000 (10:54 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Sat, 22 Mar 2025 09:54:21 +0000 (10:54 +0100)
quickjs.c
tests/microbench.js

index 09ba0e322ec0b94e3e68454dc3beca71e503c9cf..d35a333d6569811972a080fdc16c6dd136c87cc1 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -46186,7 +46186,6 @@ static void map_hash_resize(JSContext *ctx, JSMapState *s)
                                  sizeof(new_hash_table[0]) * new_hash_size, &slack);
     if (!new_hash_table)
         return;
-    new_hash_size += slack / sizeof(*new_hash_table);
 
     for(i = 0; i < new_hash_size; i++)
         init_list_head(&new_hash_table[i]);
index 871770e41d88295c3ad80223691c2466410916a7..1182c1a326a0ddccf60d413e87c5e8cc0bef22a7 100644 (file)
@@ -720,22 +720,79 @@ function bigint256_arith(n)
     return bigint_arith(n, 256);
 }
 
-function set_collection_add(n)
+function map_set(n)
 {
     var s, i, j, len = 100;
     for(j = 0; j < n; j++) {
-        s = new Set();
+        s = new Map();
         for(i = 0; i < len; i++) {
-            s.add(String(i), i);
+            s.set(String(i), i);
         }
         for(i = 0; i < len; i++) {
             if (!s.has(String(i)))
-                throw Error("bug in Set");
+                throw Error("bug in Map");
         }
     }
     return n * len;
 }
 
+function map_delete(n)
+{
+    var a, i, j;
+
+    len = 1000;
+    for(j = 0; j < n; j++) {
+        a = new Map();
+        for(i = 0; i < len; i++) {
+            a.set(String(i), i);
+        }
+        for(i = 0; i < len; i++) {
+            a.delete(String(i));
+        }
+    }
+    return len * n;
+}
+
+function weak_map_set(n)
+{
+    var a, i, j, tab;
+
+    len = 1000;
+    tab = [];
+    for(i = 0; i < len; i++) {
+        tab.push({ key: i });
+    }
+    for(j = 0; j < n; j++) {
+        a = new WeakMap();
+        for(i = 0; i < len; i++) {
+            a.set(tab[i], i);
+        }
+    }
+    return len * n;
+}
+
+function weak_map_delete(n)
+{
+    var a, i, j, tab;
+
+    len = 1000;
+    for(j = 0; j < n; j++) {
+        tab = [];
+        for(i = 0; i < len; i++) {
+            tab.push({ key: i });
+        }
+        a = new WeakMap();
+        for(i = 0; i < len; i++) {
+            a.set(tab[i], i);
+        }
+        for(i = 0; i < len; i++) {
+            tab[i] = null;
+        }
+    }
+    return len * n;
+}
+
+
 function array_for(n)
 {
     var r, i, j, sum, len = 100;
@@ -1189,7 +1246,10 @@ function main(argc, argv, g)
         func_closure_call,
         int_arith,
         float_arith,
-        set_collection_add,
+        map_set,
+        map_delete,
+        weak_map_set,
+        weak_map_delete,
         array_for,
         array_for_in,
         array_for_of,