adding dom elements jquery vs mootools vs dojo to body

JavaScript performance comparison

Revision 6 of this test case created by Miguel

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js">
</script>
<script src="//ajax.googleapis.com/ajax/libs/mootools/1.4.1/mootools-yui-compressed.js">
</script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js">
</script>
<script>
require(["dojo/dom-construct"], function(domConstruct) {
  window.domConstruct = domConstruct;
});
</script>
<div id="container"></div>
<script>
Benchmark.prototype.setup = function() {
    containerNode = document.getElementById('container');
};

Benchmark.prototype.teardown = function() {
    containerNode.innerHTML = '';
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
dojo
dojo.create('div', {
  id: 'myElement',
  innerHTML: 'This is a new element'
}, containerNode);
pending…
jquery
jQuery('<div id="myElement">This is a new element</div>').appendTo(containerNode);
pending…
mootools
new Element('div', {
  id: 'myElement',
  text: 'This is a new element'
}).inject(containerNode);
pending…
dojo 1.7 AMD
domConstruct.create('div', {
  id: 'myElement',
  innerHTML: 'This is a new element'
}, containerNode);
 
pending…
ECMAScript
var div = document.createElement('div');
div.id = 'myElement';
div.innerHTML = 'This is a new element';
containerNode.appendChild(div);
pending…
Using with block
'use strict';

var div = document.createElement('div');

with (div) {
  id = 'myElement';
  innerHTML = 'This is a new element';
}

containerNode.appendChild(div);
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:

0 comments

Add a comment