diff --git a/Makefile b/Makefile index 6d923eb..89af941 100644 --- a/Makefile +++ b/Makefile @@ -2,4 +2,6 @@ test : node speci.js x-first node speci.js y-first node speci.js mixed - node speci.js randomized + node speci.js rand-suffix + node speci.js rand-prefix + diff --git a/readme.md b/readme.md index 81dd0d4..d2c0880 100644 --- a/readme.md +++ b/readme.md @@ -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. ``` - % node speci.js -** x_first +% make test +node speci.js x-first +** x-first run 1 -72 ms +189 ms run 2 -15 ms +293 ms run 3 -22 ms +178 ms -** y_first +node speci.js y-first +** y-first run 1 -73 ms +196 ms run 2 -23 ms +175 ms run 3 -20 ms +174 ms +node speci.js mixed ** mixed run 1 -2766 ms +732 ms run 2 -52 ms +716 ms run 3 -53 ms +912 ms -** randomized +node speci.js rand-suffix +** rand-suffix run 1 -464 ms +15596 ms run 2 -445 ms +15636 ms 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 ``` diff --git a/speci.js b/speci.js index 1fa6a6e..8cf3b0d 100644 --- a/speci.js +++ b/speci.js @@ -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 buckets = 256; - //random = rando % buckets; let r = 'random' + rando; - let o = {[r]: r}; - if (Math.random() > 0.5) { - o.y = y; - o.x = x; - } else { - o.x = x; - o.y = y; - } + 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}; return o; } const million = 1000 * 1000; const n = 1 * million; - const runs = 1000 * n; + const runs = 100 * n; function bulk(filler) { let a = []; @@ -48,7 +46,8 @@ function doit(mode) { 'x-first': make_x_first, 'y-first': make_y_first, 'mixed': make_mixed, - 'randomized': make_randomized, + 'rand-prefix': make_rand_prefix, + 'rand-suffix': make_rand_suffix, }; let func = funcMap[mode]; if (!func) {