Created
December 31, 2010 16:27
-
-
Save xk/761127 to your computer and use it in GitHub Desktop.
wowAndFlutter.js
This file contains 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
// 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