jQuery: create element
JavaScript performance comparison
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="cntr"></div>
<script>
Benchmark.prototype.setup = function() {
var $eCntr = $('div#cntr'),
nCnt = 10;
function drawItem(pI) {
var eC = document.createElement('div');
eC.className = 'classDiv';
eC.setAttribute('attr1', 'somevalue'+pI);
var eP = document.createElement('p');
eP.className = 'classP';
var txt = pI+' Lorem ipsum dolor sit amet, consectetur adipiscing elit. ';
eP.appendChild(document.createTextNode(txt));
// var propTxt = (('innerText' in eP)? 'innerText' : 'textContent');
// eP[propTxt] = txt;
/*
if (eP.textContent) {
eP.textContent = txt;
} else
eP.innerText = txt;
*/
// eP.innerHtml = txt;
eC.appendChild(eP);
return eC;
}
function drawItem2(pI) {
return '<div class="classDiv" attr1="someValue'+pI+'"><p class="classP">'+ pI +' Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p></div>';
}
};
Benchmark.prototype.teardown = function() {
$eCntr.empty();
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
$(native) |
|
pending… |
$.html |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by Dmitrij
0 comments