Skip to content

Instantly share code, notes, and snippets.

@xk
Created December 31, 2010 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xk/761127 to your computer and use it in GitHub Desktop.
Save xk/761127 to your computer and use it in GitHub Desktop.
wowAndFlutter.js
// 2010-12-31 jorge@jorgechamorro.com
// JavaScript ms clock's wow and flutter
var kSample= 1e3;
var res= new Array(kSample);
var ctr;
var st= Date.now()+ 2; //start time
while (Date.now() < st) ; //get in sync with ms clock
for (var i=0; i<1e3; i++) {
st++;
ctr= 0;
while (Date.now() < st) ctr++;
res[i]= ctr;
}
var min= 1e6;
var max= -1e6;
var avg= 0;
res.forEach(function(v,i,o){
avg+= v;
if (v<min) return min=v;
if (v>max) return max=v;
});
avg/=res.length;
console.log(res);
console.log(["min:", min, ", avg:", avg, ", max:", max].join(''));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment