Jquery remove vs hide vs empty vs. detach

JavaScript performance comparison

Revision 22 of this test case created by Chele Loco

Preparation code

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

<div id="empty-me"><div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div></div>
<div id="remove-me"><div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div></div>
<div id="hide-me"><div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div></div>
<div id="detach-me"><div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div></div>
<div id="attr-me"><div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div>
<div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div></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>
    

Preparation code output

<div id="empty-me"><div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div></div> <div id="remove-me"><div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div></div> <div id="hide-me"><div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div></div> <div id="detach-me"><div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div></div> <div id="attr-me"><div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div> <div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div><div class="content">Shit</div></div>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
.remove()
window.$removed = $('#remove-me').remove();
pending…
.hide()
window.$hidden = $('#hide-me').hide();
pending…
.detach()
window.$detached = $('#detach-me').detach();
pending…
.empty()
window.$empty = $('#empty-me').empty();
pending…
.remove()#2
window.$lt = $('#remove-me:lt(10)').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.

0 Comments

Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit
Shit