jQuery .remove vs. .hide

JavaScript performance comparison

Revision 29 of this test case created

Preparation code

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<div id="remove-me"></div>
<div id="hide-me"></div>
<div id="hide-remove-me"></div>
<script>
  function init() {
   // The magic init() function will be executed once before every test
   // Still not perfect, but definitely better
   $('<div id="remove-me">').appendTo('body');
   $('<div id="hide-remove-me">').appendTo('body');
   $('#hide-me').show();
   $('#hide-remove-me').show();
  }
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
.remove()
$('#remove-me').remove();
pending…
.hide()
$('#hide-me').hide();
pending…
'.hide().remove()'
$('#hide-remove-me').hide().remove();
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