Skip to content

Instantly share code, notes, and snippets.

@uu59
Last active August 29, 2015 13:56
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 uu59/8917193 to your computer and use it in GitHub Desktop.
Save uu59/8917193 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<script>
var workers = [];
for(var i=0; i<4; i++){
var worker = new Worker("calc.js");
worker.onmessage = function(e){
console.log(e.data);
console.log(Date.now() - start);
}
workers.push(worker);
}
var last = 999999;
var step = Math.ceil(last / workers.length);
var start = Date.now();
for(var i=0; i<workers.length; i++){
workers[i].postMessage([step * i, step * (i+1)]);
}
</script>
</body></html>
importScripts("http://www.myersdaily.org/joseph/javascript/md5.js");
onmessage = function(e){
var salt = "hoge";
var correct = "4b364677946ccf79f841114e73ccaf4f";
for(var i = e.data[0]; i<e.data[1]; ++i){
if(md5(salt + "$" +("000000"+i).slice(-6)) === correct){
postMessage(i);
self.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment