WebWorker vs Single Thread (v4)

Revision 4 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Single thread
var sum = 0;
for (var i = 1; i <= 4000000; i++)
sum += i;
ready
Four thread
// async test
var threads = [];
var sum = 0;
var count = 4;
for (var i = 0; i < 4; i++) {
  (function(i) {
    var code = 'var sum = 0; for(var i = ' + (i * 1E6 + 1) + '; i<= ' + ((i + 1) * 1E6) + '; i++) sum += i;postMessage(sum);';
    var bb = new Blob([code], {
      type: 'text/javascript'
    });
    var bbURL = URL.createObjectURL(bb);
    var worker = new Worker(bbURL);
    worker.onmessage = function(e) {
      sum += e.data;
      URL.revokeObjectURL(bbURL);
      if (--count === 0) {
        threads = null;
        deferred.resolve();
      }
    };
    threads.push(worker);
  }(i));
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.