postMessage

JavaScript performance comparison

Test case created

Preparation code

<iframe src="data:text/html;base64, PHNjcmlwdD53aW5kb3cuYWRkRXZlbnRMaXN0ZW5lcignbWVzc2FnZScsZnVuY3Rpb24oKXt0b3AucG9zdE1lc3NhZ2UoJ2EnLCcqJyl9KTwvc2NyaXB0Pg=="></iframe>

<!--
<script>window.addEventListener('message',function(){top.postMessage('a','*')})</script>
-->
<script>
Benchmark.prototype.teardown = function() {
    window.removeEventListener('message', window.onMessage);
};
</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
postMessage
// async test
var iter = 1000;

window.onMessage = function() {
  if (!iter--) {
    deferred.resolve();
    return
  }
  iframeWindow.postMessage('asdf', '*');
}

window.addEventListener('message', window.onMessage, false);

iframeWindow = document.querySelector('iframe').contentWindow;
start = +new Date;
iframeWindow.postMessage('asdf', '*');
pending…
postMessage2
// async test
var iter = 1000;

window.onMessage = function() {
  if (!iter--) {
    deferred.resolve();
    return
  }
  iframeWindow.postMessage('asdf', '*');
}

window.addEventListener('message', window.onMessage, false);

iframeWindow = document.querySelector('iframe').contentWindow;
start = +new Date;
iframeWindow.postMessage('asdf', '*');
pending…

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

Compare results of other browsers

0 comments

Add a comment