This commit is contained in:
Brooke Vibber 2023-09-04 10:23:59 -07:00
parent 7878913dd9
commit 5e084b9a71
3 changed files with 46 additions and 30 deletions

View file

@ -2,4 +2,6 @@ test :
node speci.js x-first node speci.js x-first
node speci.js y-first node speci.js y-first
node speci.js mixed node speci.js mixed
node speci.js randomized node speci.js rand-suffix
node speci.js rand-prefix

View file

@ -9,44 +9,59 @@ handle a couple of different variants -- but this might not be true of all
possibilities. 256 randomized variants is linearly slower. possibilities. 256 randomized variants is linearly slower.
``` ```
% node speci.js % make test
** x_first node speci.js x-first
** x-first
run 1 run 1
72 ms 189 ms
run 2 run 2
15 ms 293 ms
run 3 run 3
22 ms 178 ms
** y_first node speci.js y-first
** y-first
run 1 run 1
73 ms 196 ms
run 2 run 2
23 ms 175 ms
run 3 run 3
20 ms 174 ms
node speci.js mixed
** mixed ** mixed
run 1 run 1
2766 ms 732 ms
run 2 run 2
52 ms 716 ms
run 3 run 3
53 ms 912 ms
** randomized node speci.js rand-suffix
** rand-suffix
run 1 run 1
464 ms 15596 ms
run 2 run 2
445 ms 15636 ms
run 3 run 3
445 ms 15501 ms
node speci.js rand-prefix
** rand-prefix
run 1
18896 ms
run 2
18883 ms
run 3
18784 ms
``` ```

View file

@ -16,25 +16,23 @@ function doit(mode) {
} }
} }
function make_randomized(x, y) { function make_rand_prefix(x, y) {
let rando = (Math.random() * (2 ** 32 - 1)) | 0; let rando = (Math.random() * (2 ** 32 - 1)) | 0;
//let buckets = 256;
//random = rando % buckets;
let r = 'random' + rando; let r = 'random' + rando;
let o = {[r]: r}; let o = {[r]: r, x, y};
if (Math.random() > 0.5) { return o;
o.y = y;
o.x = x;
} else {
o.x = x;
o.y = y;
} }
function make_rand_suffix(x, y) {
let rando = (Math.random() * (2 ** 32 - 1)) | 0;
let r = 'random' + rando;
let o = {x, y, [r]: r};
return o; return o;
} }
const million = 1000 * 1000; const million = 1000 * 1000;
const n = 1 * million; const n = 1 * million;
const runs = 1000 * n; const runs = 100 * n;
function bulk(filler) { function bulk(filler) {
let a = []; let a = [];
@ -48,7 +46,8 @@ function doit(mode) {
'x-first': make_x_first, 'x-first': make_x_first,
'y-first': make_y_first, 'y-first': make_y_first,
'mixed': make_mixed, 'mixed': make_mixed,
'randomized': make_randomized, 'rand-prefix': make_rand_prefix,
'rand-suffix': make_rand_suffix,
}; };
let func = funcMap[mode]; let func = funcMap[mode];
if (!func) { if (!func) {