Select body tag by nodeName versus document.body

Benchmark created by Craig Patik on


Description

I want to see if there is any look-up cost involved with specifying the tag name 'body' rather than the direct object document.body

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  $('body').addClass('test');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Node name
if ($('body').is('.test')) {
 var x = $('body').attr('class');
}
ready
Direct object
if ($(document.body).is('.test')) {
 var x = $(document.body).attr('class');
}
ready

Revisions

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

  • Revision 1: published by Craig Patik on