jQuery .remove vs. .hide vs. detach (v15)

Revision 15 of this benchmark created by fghfgh on


Preparation HTML

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

<div id="remove-me">
<input/><input/><input/><input/><input/><input/>
</div>
<div id="hide-me"><input/><input/><input/><input/><input/><input/></div>
<div id="detach-me"><input/><input/><input/><input/><input/><input/></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');
   $('#hide-me').show();
   if (window.$detached != null) {
    window.$detached.appendTo('body');
   }
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
.remove()
window.$removed = $('#remove-me').children().remove();
ready
.hide()
window.$hidden = $('#hide-me').hide();
ready
empty
window.$detached = $('#detach-me').empty();
ready

Revisions

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