Remove v.s. Detach vs hide vs empty vs "" (v41)

Revision 41 of this benchmark created on


Preparation HTML

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

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

Setup

var $inner = '<div class="sup"></div><div class="sup"></div><div class="sup"></div><div class="sup"></div><div class="sup"></div>';
  
  $('#html').html($inner);
  
  var $html = $('#html');

Teardown



            // need something like this to reset target
  $('#html').empty().html($inner);
        
  

Test runner

Ready to run.

Testing in
TestOps/sec
Remove
$('.sup').remove();
ready
Hide
$('.sup').hide();
ready
detach
$('.sup').detach();
ready
html('')
$('#html').html('');
ready
empty()
$('#html').empty();
ready
innerText = null
$("#html")[0].innerText = null;
ready
hybrid
var el = $("#html")[0];
while (el.firstChild) { el.removeChild(el.lastChild) }
ready
.find
$html.find('.sup').remove();
ready

Revisions

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