Remove v.s. Detach vs hide vs empty vs ""

JavaScript performance comparison

Revision 40 of this test case created by

Preparation code

<script src="https://code.jquery.com/jquery-git2.min.js"></script>

<div id="html"></div>




      
<script>
Benchmark.prototype.setup = function() {
  var $inner = '<div id="sup"></div><div id="sup"></div><div id="sup"></div><div id="sup"></div><div id="sup"></div>';
  
  $('#html').html($inner);

};

Benchmark.prototype.teardown = function() {
  // need something like this to reset target
  $('#html').empty().html($inner);

};
</script>

Preparation code output

<div id="html"></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
$('#sup').remove();
pending…
Hide
$('#sup').hide();
pending…
detach
$('#sup').detach();
pending…
html('')
$('#html').html('');
pending…
empty()
$('#html').empty();
pending…
innerText = null
$("#html")[0].innerText = null;
pending…
hybrid
var el = $("#html")[0];
while (el.firstChild) { el.removeChild(el.lastChild) }
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