From 5e030cba07e39b7a6acbc2ffa9dee7f10c8a2d83 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 4 Sep 2023 07:51:56 -0700 Subject: [PATCH] add 256-bucket variant, slower ! --- speci.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/speci.js b/speci.js index 9b39db5..3b31dcf 100644 --- a/speci.js +++ b/speci.js @@ -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(); \ No newline at end of file