Last active
February 9, 2017 05:56
-
-
Save dazld/f3034f1380d3e87d6e20da5c14e84742 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ma = require('moving-average')(10000); | |
const log = (a)=>{ console.log(a); return a} | |
let run = true; | |
log(process.version) | |
function count(){ | |
const now = Date.now(); | |
return new Promise(function(res, rej){ | |
const vals = Array(9e4).fill('').map(_ => Math.random()); | |
vals.reduce((t,v) => {return t + v}, 0); | |
res({time: Date.now() - now}) | |
}); | |
} | |
function delay(){ | |
return new Promise(res => setTimeout(res.bind(null, ...arguments), 100)) | |
} | |
function operate(){ | |
run = count() | |
// .then(log) | |
.then(delay) | |
.then(t => ma.push(Date.now(), t.time)) | |
.then(function(){ | |
const doit = Date.now() % 10 == 0; | |
if (doit) console.log(ma.movingAverage() << 0) | |
}) | |
.then(operate) | |
} | |
process.on('SIGINT', ()=>{ | |
run.then(()=>log('ending')).then(process.exit.bind(null, 0)) | |
}) | |
operate() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "ma", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"moving-average": "^0.1.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment