Cool, I like simplicity of your code. I want to try similar implementation in javascript. Partially because of curiosity and partialy because (inspired by hashcash) it can generate few hashes by fighting comments spam :-).
I just made few tests. In four javascript threads I get ~4khash/s, which is EXTREMELY slow. Probably because javascript is interpreted and without any JIT yet. Would be great if javascript supports GPU. Flash will support GPU soon, so we will see
.
I do find the idea of web sites generating bitcoins using their visitor browsers very entertaining. If nothing else, it's a novel idea to monetize your traffic without having to hope your ad network won't get moody on you. Also, a little devious. No downside.
Random ideas in no particular order:
- Flash Pixel Bender. GPU-rendered shaders. Not too sure how practical it is to use that to compute hashes.
- WebGL. more GPU-rendered stuff. meant for graphics too. see above.
- Web Workers: where available, will allow CPU-intensive JS code to run without noticeably slowing down the browser UI. Unfortunately, can't be used to control GPU approaches, but good as a CPU fallback method. Note that many JS engines are using JITs now. you'll get very different results on different browsers.
- unload event handler using a synchronous XHR: fairly reliable way to sync up whatever the browser computed back to a server when the user navigates away. except on some browsers, where periodic syncs are the only way.
Mix it all in a bag, use shaders creatively ( maybe a pixel could encode whether a bunch of hashes met some criteria for example), and you might get hashrates that don't totally suck, multiplied by whatever amount of traffic your site gets.
Interestingly, if the hashrates somehow approached what a real GPGPU solution can output (unlikely as that may be), then miner pooling sites could offer install-less approaches to participate in the pool..