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
jQuery way : create a document-fragment of the complex html string (is it appended to the document after creation?) and then modify properties while traversing using jquery methods. Finally its appended to the target element (i hope i am understanding this correctly).
Native js way: The complex dom structure to be created is laid out in a hash first. The hash is then passed through a 'create' method that recursively generates each tag (and its attributes) using native js methods and appends to a document-fragment which is then appended to the target element
<style type="text/css">
h3{margin: 15px 0 0;color:rgb(120,120,120);}
li{ margin: 2px 0;overflow: auto; border:1px solid rgb(240,240,240);}
.left{ float: left;margin:0 5px 0 0; color: gray;}
.right{float: right; color: orange;}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<h3>Recursive DOM creation</h3>
<ul id="append-native-here">
</ul>
<h3>jQuery DOM creation</h3>
<ul id="append-jquery-here">
</ul>
<script>
var myApp = {};
myApp.dom = {
tag: 'li',
class: 'selected',
title: 'A list item',
content: [{
tag: 'span',
text: 'I am a span',
class: 'left'
},
{
tag: 'span',
class: 'right',
text: 'I am a second span'
},
{
tag: 'input',
type: 'hidden',
name: 'selector_object[]',
value: 10
}]
};
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Recursive DOM creation |
| ready |
jQuery's DOM creation |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.