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 the performance of adding elements to the DOM by using strings and innerHTML, creating the DOMElement node tree and appending with appendChild(), and using jQuery to replace content with $elm.html().
<!-- Existing DOM elements into which the tests will append new content -->
<div id="parent-inject">
Replace me via
<code>
elm.innerHTML()
</code>
</div>
<hr/>
<div id="parent-create">
Replace me via
<code>
elm.appendChild()
</code>
</div>
<hr/>
<div id="parent-jquery">
Replace me via
<code>
$elm.html()
</code>
</div>
<hr/>
<div id="parent-iframe">
Replace me via parsing in hidden iframe
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
/***
* Create a realistic, level playing field by storing references to container
* elements beforehand, as you would likely do in a real webapp.
***/
// Existing DOM elements into which the tests will append new content
var parentInject = document.getElementById('parent-inject');
var parentCreate = document.getElementById('parent-create');
var $parentJQuery = $('#parent-jquery');
var parentIframe = document.getElementById('parent-iframe');
// This content string is assigned to a variable in each loop of each test.
var contentString1 = '<div class="test" onmousemove="myFunction('
var contentString2 = ')"><h1>This is a test</h1><p>This is only a test</p></div>';
// see: https://community.jboss.org/people/wesleyhales/blog/2011/08/28/fixing-ajax-on-mobile-devices
window.getFrame = function() {
var frame = document.getElementById("temp-frame");
if (!frame) {
// create frame
frame = document.createElement("iframe");
frame.setAttribute("id", "temp-frame");
frame.setAttribute("name", "temp-frame");
frame.setAttribute("seamless", "");
frame.setAttribute("sandbox", "");
frame.style.display = 'none';
document.documentElement.appendChild(frame);
}
return frame.contentDocument;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
innerHTML |
| ready |
createElement() and appendChild() |
| ready |
jQuery.fn.html() |
| ready |
iframe parsing |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.