Add attributes natively with jQuery selection

JavaScript performance comparison

Revision 2 of this test case created by cacajean

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
Benchmark.prototype.teardown = function() {
    console.log(a);
};
</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
Full Native
var a = document.createElement('a');
a.href = 'http://www.lala.co.uk';
a.className = 'class-a';
a.innerText = 'this is a link';
a= $(a);
pending…
with jQuery.get()
var a = $(document.createElement('a'));
a.get(0).href = 'http://www.lala.co.uk';
a.get(0).className = 'class-a';
a.get(0).innerText = 'this is a link';
pending…
with jQuery index
var a = $(document.createElement('a'));
a[0].href = 'http://www.lala.co.uk';
a[0].className = 'class-a';
a[0].innerText = 'this is a link';
pending…
full jQuery with native createElement
var a = $(document.createElement('a'));
a.attr({
href: 'http://www.lala.co.uk',
class: 'class-a'}).text('this is a link');
pending…
pure jQuery
var a = $('<a/>');
a.attr({
href: 'http://www.lala.co.uk',
class: 'class-a'}).text('this is a link');
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