unwrap vs replacewith

Benchmark created by Nick Craver on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="bob"></div>
<script>
  var bob = document.getElementById("bob");
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
unwrap
bob.innerHTML = "A nice house was found in <b>Toronto</b>.";
$('b', bob).contents().unwrap();
ready
replace with contents
bob.innerHTML = "A nice house was found in <b>Toronto</b>.";
$("b", bob).replaceWith(function() {
 return $(this).contents();
});
ready
replace with innerHTML
bob.innerHTML = "A nice house was found in <b>Toronto</b>.";
$("b", bob).replaceWith(function() {
 return this.innerHTML;
});
ready

Revisions

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