Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ cmake-*
out/
CMakeUserPresets.json
fuzz
.vscode/
.vscode/
microbench*.txt
6 changes: 2 additions & 4 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -48645,7 +48645,6 @@ static JSMapRecord *map_find_record(JSContext *ctx, JSMapState *s,
static void map_hash_resize(JSContext *ctx, JSMapState *s)
{
uint32_t new_hash_size, i, h;
size_t slack;
struct list_head *new_hash_table, *el;
JSMapRecord *mr;

Expand All @@ -48654,11 +48653,10 @@ static void map_hash_resize(JSContext *ctx, JSMapState *s)
new_hash_size = 4;
else
new_hash_size = s->hash_size * 2;
new_hash_table = js_realloc2(ctx, s->hash_table,
sizeof(new_hash_table[0]) * new_hash_size, &slack);
new_hash_table = js_realloc(ctx, s->hash_table,
sizeof(new_hash_table[0]) * new_hash_size);
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]);
Expand Down
69 changes: 64 additions & 5 deletions tests/microbench.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,22 +578,78 @@ function bigint256_arith(n)
return bigint_arith(n, 256);
}

function set_collection_add(n)
function map_set(n)
{
var s, i, j, len = 100;
s = new Set();
for(j = 0; j < n; j++) {
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;

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, len, 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, len, 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;
Expand Down Expand Up @@ -1034,7 +1090,10 @@ function main(argc, argv, g)
closure_var,
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,
Expand Down