jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Compares performance of nested iframes communication using postMessage, YUI sandboxing (no postMessage) and direct access to parent. The test consists of 100 nested iframes, performing message passing starting from the innermost iframe to the outermost one, then again starting from inner iframe #50, #10, #5 and #2 to outermost one.
<script>
var i, iframe, idoc,
doc = document,
body = doc.body,
numIFrames = 100,
writeMessage = function (e) {
var data = parseInt(e.data, 10);
document.getElementById('msg').innerHTML = data;
data += 1;
parent.postMessage(data, '*');
},
getIframe = function (n) {
var idoc,
iframe = doc.getElementsByTagName('iframe')[0];
for (i = 0; i < n; i += 1) {
idoc = iframe.contentWindow.document;
iframe = idoc.getElementsByTagName('iframe')[0];
}
return iframe.contentWindow;
};
iframe = doc.createElement('iframe');
body.appendChild(iframe);
for (i = 0; i < numIFrames; i += 1) {
idoc = iframe.contentWindow.document;
idoc.open().write(
'<!doctype html>' +
'<html>' +
' <head>' +
' <script>' +
' window.addEventListener("message", ' +
writeMessage.toString() +
' , false);' +
' <\/script>' +
' </head>' +
' <body>' +
' <div id="msg"></div>' +
(i < numIFrames - 1? '<iframe></iframe>' : '') +
' <script src="http://yui.yahooapis.com/3.5.1/build/yui/yui-min.js"><\/script>' +
' <script>' +
' YUI({' +
' win: window.parent, ' +
' doc: window.parent.document' +
' }).use(function (Y) {' +
' YUI.Env.msg = function (m) {' +
' document.getElementById("msg").innerHTML = m;' +
' if (Y.config.win.YUI) Y.config.win.YUI.Env.msg(m + 1);' +
' };' +
' });' +
' <\/script>' +
' <script>' +
' window._msg = function (m) {' +
' document.getElementById("msg").innerHTML = m;' +
' if (window.parent._msg) window.parent._msg(m + 1);' +
' };' +
' <\/script>' +
' </body>' +
'</html>'
);
idoc.close();
if (i < numIFrames - 1) {
iframe = idoc.getElementsByTagName('iframe')[0];
}
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
100 postMessage |
| ready |
100 YUI |
| ready |
100 parent |
| ready |
50 postMessage |
| ready |
50 YUI |
| ready |
50 parent |
| ready |
10 postMessage |
| ready |
10 YUI |
| ready |
10 parent |
| ready |
5 postMessage |
| ready |
5 YUI |
| ready |
5 parent |
| ready |
2 postMessage |
| ready |
2 YUI |
| ready |
2 parent |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.