Compare commits

..

No commits in common. "5e084b9a7143f76b51341c9261c8e47a7d63ca15" and "7dd97f6543fe53e92c5b671c49f3f021d75ff602" have entirely different histories.

3 changed files with 48 additions and 73 deletions

View file

@ -1,7 +0,0 @@
test :
node speci.js x-first
node speci.js y-first
node speci.js mixed
node speci.js rand-suffix
node speci.js rand-prefix

View file

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

View file

@ -1,4 +1,4 @@
function doit(mode) {
function doit() {
function make_x_first(x,y) {
return {x, y};
@ -16,23 +16,23 @@ function doit(mode) {
}
}
function make_rand_prefix(x, y) {
function make_randomized(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};
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 = 1 * million;
const runs = 100 * n;
const n = 10 * million;
function bulk(filler) {
let a = [];
@ -42,22 +42,10 @@ function doit(mode) {
return a;
}
let funcMap = {
'x-first': make_x_first,
'y-first': make_y_first,
'mixed': make_mixed,
'rand-prefix': make_rand_prefix,
'rand-suffix': make_rand_suffix,
};
let func = funcMap[mode];
if (!func) {
console.log(`Pass as parameter one of:`);
for (let key of Object.keys(funcMap)) {
console.log(` ${key}`);
}
process.exit(1);
}
const data = bulk(func);
const x_first = bulk(make_x_first);
const y_first = bulk(make_y_first);
const mixed = bulk(make_mixed);
const randomized = bulk(make_randomized);
function time(func) {
const start = Date.now();
@ -76,8 +64,8 @@ function doit(mode) {
console.log(`run ${i+1}`);
report(() => {
let sumX = 0, sumY = 0;
for (let i = 0; i < runs; i++) {
let item = dataSet[i % dataSet.length];
for (let i = 0; i < dataSet.length; i++) {
let item = dataSet[i];
sumX += item.x;
sumY += item.y;
}
@ -87,9 +75,18 @@ function doit(mode) {
}
}
console.log(`** ${mode}`);
demo(data);
console.log(`** x_first`);
demo(x_first);
console.log(`** y_first`);
demo(y_first);
console.log(`** mixed`);
demo(mixed);
console.log(`** randomized`);
demo(randomized);
}
let mode = String(process.argv[2]);
doit(mode);
doit();