body select by id or tag name

Benchmark created by amenthes on


Description

I wondered, how performance is when you are using the tag name for a (by definition) singular element.

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
 var a, b, c, d;
 $('body').attr('id', 'test123');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQ + ID
a = $('#test123');
a.height();
ready
jQ + tag name
b = $('body');
b.height();
ready
DOM + ID
c = document.getElementById('test123');
$(c).height();
ready
DOM + tag name
d = document.getElementsByTagName('body');
$(d).height();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by amenthes on