Zepto .remove vs. .hide vs. detach

JavaScript performance comparison

Revision 44 of this test case created by agm

Preparation code

<script src="http://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.3/zepto.min.js">
</script>
<div id="remove-me">
  confirm removed
</div>
<div id="hide-me">
  confirm hidden
</div>
<div id="detach-me">
  confirm detached
</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>
      
<script>
Benchmark.prototype.setup = function() {
  var $detach = $("#detach-me");
  var $remove = $('#remove-me');
  var $hide = $('#hide-me');
  var hide = document.getElementById('hide-me');

};
</script>

Preparation code output

<div id="remove-me"> confirm removed </div> <div id="hide-me"> confirm hidden </div> <div id="detach-me"> confirm detached </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.remove();
pending…
.hide()
window.$hidden = $hide.hide();
pending…
.detach()
window.$detached = $detach.detach();
pending…
style.display
hide.style.display = 'none';
pending…
.css('display','none')
window.$detached = $detach.css('display', 'none');
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

confirm removed
confirm hidden
confirm detached