Skip to content

Commit

Permalink
test: stddev
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Mar 1, 2017
1 parent 3257c00 commit 7086df2
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ function measure(json) {
};

let lavg = 0;
let ldev = 0;
let havg = 0;
let hdev = 0;
let count = 0;
for (;;) {
let low;
Expand All @@ -49,14 +51,31 @@ for (;;) {
const jLow = genProbeJSON(postfix, low);
const jHigh = genProbeJSON(postfix, high);

let lt;
let ht;
if (Math.random() < 0.5) {
lavg += measure(jLow);
havg += measure(jHigh);
lt = measure(jLow);
ht = measure(jHigh);
} else {
havg += measure(jHigh);
lavg += measure(jLow);
ht = measure(jLow);
lt = measure(jHigh);
}
lavg += lt;
havg += lt;
ldev += Math.pow(lt, 2);
hdev += Math.pow(ht, 2);
count++;

console.log('%d %d', (lavg / count).toFixed(1), (havg / count).toFixed(1));
let ltdev = ldev / count;
ltdev -= Math.pow(lavg / count, 2);
ltdev = Math.sqrt(ltdev);
let htdev = hdev / count;
htdev -= Math.pow(havg / count, 2);
htdev = Math.sqrt(htdev);

console.log('left=%d ldev=%d right=%d rdev=%d',
(lavg / count).toFixed(1),
ltdev.toFixed(1),
(havg / count).toFixed(1),
htdev.toFixed(1));
}

0 comments on commit 7086df2

Please sign in to comment.