summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFabrice Bellard <fabrice@bellard.org>2025-03-22 10:54:21 +0100
committerFabrice Bellard <fabrice@bellard.org>2025-03-22 10:54:21 +0100
commit49413985ebb00315443597f5e04d0df1418ffdbc (patch)
tree4fd5a86fb329f50a6a3ba7a88d3c15f8897737e3 /tests
parent9f65ef1950c61e20800b8f84da2082b35bbb894c (diff)
downloadquickjs-49413985ebb00315443597f5e04d0df1418ffdbc.tar.gz
quickjs-49413985ebb00315443597f5e04d0df1418ffdbc.zip
fixed hash_map_resize() - added Map/WeakMap in microbench
Diffstat (limited to 'tests')
-rw-r--r--tests/microbench.js70
1 files changed, 65 insertions, 5 deletions
diff --git a/tests/microbench.js b/tests/microbench.js
index 871770e..1182c1a 100644
--- a/tests/microbench.js
+++ b/tests/microbench.js
@@ -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,