Web worker data copying performance

JavaScript performance comparison

Revision 2 of this test case created

Info

Compare the time taken to copy large Typed arrays from the main thread to a WebWorker and back.

Note: Only browsers which support StructureCloning will be able to copy Typed arrays.

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script type="javascript/worker" id="workerFunc">
  self.onmessage = function(e) {
    postMessage(e.data); // Pass through
  };
</script>

<script type="text/javascript">
$(function() {
console.log("Creating data arrays");

var data32mb = new Uint8Array(1024 * 1024 * 32);
var data1mb = new Uint8Array(1024 * 1024);
for (var i=0; i<data32mb.length; i++) {
  data32mb[i] = parseInt(Math.random()* 256);
  if (data1mb.length > i) {
    data1mb[i] = data32mb[i];
  }
}
window.data32mb = data32mb;
window.data1mb = data1mb;

console.log("Creating web worker");

window.URL = window.URL || window.webkitURL || null;
var script = document.querySelector('#workerFunc');
var blob = new Blob([script.textContent]);
window.testWorker = new Worker(window.URL.createObjectURL(blob));

console.log("Setup complete");
});
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Uint8Array
// async test
window.testWorker.onmessage = function(e) {
  deferred.resolve();
};
window.testWorker.postMessage(window.data32mb);
 
pending…
arraybuffer
// async test
window.testWorker.onmessage = function(e) {
  deferred.resolve();
};
window.testWorker.postMessage(window.data32mb.buffer);
 
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment