add 256-bucket variant, slower !

This commit is contained in:
Brooke Vibber 2023-09-04 07:51:56 -07:00
parent 0592fb71f9
commit 5e030cba07

View file

@ -8,7 +8,7 @@ function doit() {
return {y, x};
}
function make_random(x, y) {
function make_mixed(x, y) {
if (Math.random() > 0.5) {
return make_y_first(x, y);
} else {
@ -16,6 +16,21 @@ function doit() {
}
}
function make_randomized(x, y) {
let rando = (Math.random() * (2 ** 32 - 1)) | 0;
let buckets = 256;
let r = 'random' + (rando % buckets);
let o = {[r]: r};
if (Math.random() > 0.5) {
o.y = y;
o.x = x;
} else {
o.x = x;
o.y = y;
}
return o;
}
const million = 1000 * 1000;
const n = 10 * million;
@ -29,7 +44,8 @@ function doit() {
const x_first = bulk(make_x_first);
const y_first = bulk(make_y_first);
const mixed = bulk(make_random);
const mixed = bulk(make_mixed);
const randomized = bulk(make_randomized);
function time(func) {
const start = Date.now();
@ -68,6 +84,9 @@ function doit() {
console.log(`** mixed`);
demo(mixed);
console.log(`** randomized`);
demo(randomized);
}
doit();