id vs data id

JavaScript performance comparison

Revision 4 of this test case created

Preparation code

<span id="foo" data-id="foo">
  Foo
</span>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>

Preparation code output

Foo

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:ID
$('#id').css('border', '1px solid red');
pending…
JQUERY:data-id (param)
$('[data-id="foo"]').css('border', '1px solid red');
pending…
getElementById
var a = document.getElementById("foo").style.border;
a.width = "1px";
a.style = "solid";
a.color = "red";
pending…
getElementById 2
var a = document.getElementById("foo");
a.style.border = "1px solid red";
pending…
jQuery:element attr id
$('span[id="foo"]').css('border', '1px solid red');
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