This commit is contained in:
Brooke Vibber 2023-09-04 10:27:40 -07:00
parent 5e084b9a71
commit 35e744eacc
2 changed files with 14 additions and 13 deletions

View file

@ -1,12 +1,8 @@
# speci.js - specialization benchmark test
Tests two-property objects with {x, y} or {y, x} and access in a tight loop
When the array contains consistent elements it optimizes well, but the first
run is much slower on a randomly mixed array.
Subsequent runs come up much faster as the higher-tier compilers in V8 can
handle a couple of different variants -- but this might not be true of all
possibilities. 256 randomized variants is linearly slower.
When the array contains consistent elements it optimizes well, but slows down
as you add variants, and slows down A LOT if you add other random properties
```
% make test

View file

@ -16,17 +16,22 @@ function doit(mode) {
}
}
function make_rand_prefix(x, y) {
let rando = (Math.random() * (2 ** 32 - 1)) | 0;
let r = 'random' + rando;
let o = {[r]: r, x, y};
return o;
}
function make_rand_suffix(x, y) {
let rando = (Math.random() * (2 ** 32 - 1)) | 0;
let r = 'random' + rando;
let o = {x, y, [r]: r};
// Equivalent to:
//let o = make_x_first(x, y);
//o[r] = r;
return o;
}
function make_rand_prefix(x, y) {
let rando = (Math.random() * (2 ** 32 - 1)) | 0;
let r = 'random' + rando;
let o = {[r]: r, x, y};
return o;
}