jquery toggle vs conditional show hide

Benchmark created by Dan Manastireanu on


Preparation HTML

<div id="div">this is a div</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  var show = true,
      hide = false;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
toggle
$('#div').toggle(show);
$('#div').toggle(hide);
ready
conditional show hide
$('#div')[show ? 'show' : 'hide']();
$('#div')[hide ? 'show' : 'hide']();
ready

Revisions

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

  • Revision 1: published by Dan Manastireanu on