conditional: global variable vs jquery element exists

Benchmark created on


Preparation HTML

<div id="div1"></div>
<div id="not_div2"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  var section = 'portfolio',
      not_section = 'not_portfolio';
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
global variable true
if (section === 'portfolio') true;
ready
global variable false
if (not_section === 'portfolio') true;
ready
element exists
if ($('#div1').length > 0) true;
ready
element does not exist
if ($('#div2').length > 0) true;
ready

Revisions

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