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>
<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');
// 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>';
Ready to run.
Test | Ops/sec | |
---|---|---|
innerHTML |
| ready |
createElement() and appendChild() |
| ready |
jQuery.fn.html() |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.