diff --git a/readme.md b/readme.md index d2c0880..17a858e 100644 --- a/readme.md +++ b/readme.md @@ -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 diff --git a/speci.js b/speci.js index 8cf3b0d..4dc64ca 100644 --- a/speci.js +++ b/speci.js @@ -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; }