Compare commits

...

3 commits

Author SHA1 Message Date
5e084b9a71 whee 2023-09-04 10:23:59 -07:00
7878913dd9 makefile test 2023-09-04 10:19:17 -07:00
f7a6a4ab02 dataset 2023-09-04 10:14:07 -07:00
3 changed files with 73 additions and 48 deletions

7
Makefile Normal file
View file

@ -0,0 +1,7 @@
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,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
```

View file

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