jquery vs createElement with class2

JavaScript performance comparison

Revision 14 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    var props = {
        'class': 'className'
    };
   
    function ce(tag) {
        return document.createElement(tag);
    }
   
    function ce2(tag, opts) {
        return $(document.createElement(tag), opts);
    }
   
    function ce3(tag, opts) {
        var ele = document.createElement(tag);
        for(var k in opts) {
            ele[k] = opts[k];
        }
        return $(ele);
    }
};
</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
jquery (HTML)
var test = $('<span class="testClass">');
pending…
createElement
var test = $(document.createElement('span'));
test.className = "testClass";
pending…
jQuery (Object)
var test = $('<span>', {
  'class': 'testClass'
})
pending…
jQuery (createElement)
var test = $(document.createElement('span'), {
  'class': 'testClass'
})
pending…
jQuery (ce)
var test = $(ce('span'), {
  'class': 'testClass'
})
pending…
jQuery (ce2)
var test = ce2('span', {
  'class': 'testClass'
})
pending…
jQuery (ce3)
var test = ce3('span', {
  'className': 'testClass'
})
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