Web Workers handling AJAX calls - optimisation overkill?

JavaScript performance comparison

Revision 2 of this test case created by Konrad Dzwinel

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function getData() {
    var jsonString = '{"coord":{"lon":-0.13,"lat":51.51},"sys":{"type":1,"id":5091,"message":0.8232,"country":"GB","sunrise":1412575813,"sunset":1412616405},"weather":[{"id":520,"main":"Rain","description":"light intensity shower rain","icon":"09d"},{"id":310,"main":"Drizzle","description":"light intensity drizzle rain","icon":"09d"}],"base":"cmc stations","main":{"temp":284.96,"pressure":1001,"humidity":81,"temp_min":283.15,"temp_max":286.35},"wind":{"speed":5.1,"deg":170,"var_beg":140,"var_end":210,"gust":11.3},"clouds":{"all":75},"dt":1412602600,"id":2643743,"name":"London","cod":200}';
    
    var ajaxCall = new XMLHttpRequest();
    return JSON.parse(jsonString);
  }
  
  var URL = window.URL || window.webkitURL || window.mozURL || window.msURL || window.oURL;
  
  var code = getData.toString() + 'onmessage = function(e) {postMessage(getData());};';
  var bb = new Blob([code], {type: 'text/javascript'});
  var bbURL = URL.createObjectURL(bb);
  var worker = new Worker(bbURL);
  worker.onmessage = function () {
    deferred.resolve();
  };

};

Benchmark.prototype.teardown = function() {
  worker.terminate();
  URL.revokeObjectURL(bbURL);

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Without WebWorkers
getData();
pending…
With WebWorkers
// async test
worker.postMessage("");//worker will run `getData` and return the result
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.

0 Comments