Created
July 19, 2012 09:25
-
-
Save josejuan/3142648 to your computer and use it in GitHub Desktop.
bigJob
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
// Calculamos Pi enviando datos cada X tiempo | |
function Pi(MaxMilliSegs) { | |
var T, H, t, r = 0; | |
var rst = function () { | |
T = H = 0; | |
t = MaxMilliSegs + ~~new Date(); | |
}; | |
rst(); | |
while(1) { | |
// para no andar mirando el tiempo | |
if(++r > 10000) { | |
// notificamos? | |
if(~~new Date() > t) { | |
postMessage({T: T, H: H}); | |
rst(); | |
} | |
r = 0; | |
} | |
// calculamos hit | |
++T; | |
var x = Math.random(); | |
var y = Math.random(); | |
if(x * x + y * y < 1.0) H++; | |
} | |
} | |
// nos ponemos en marcha y no paramos | |
onmessage = function(args) { | |
Pi(args.data); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment