Jquery remove vs hide vs empty vs. detach (v21)

Revision 21 of this benchmark created on


Preparation HTML

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

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

Test runner

Ready to run.

Testing in
TestOps/sec
.remove()
window.$removed = $('#remove-me').remove();
ready
.hide()
window.$hidden = $('#hide-me').hide();
ready
.detach()
window.$detached = $('#detach-me').detach();
ready
.empty()
window.$empty = $('#empty-me').empty();
ready
.attr()
window.$attr = $('#attr-me').attr('style', 'display:none;');
ready

Revisions

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