reverse().forEach() vs. forEach() iteration with removeChild (v2)

Revision 2 of this benchmark created by Erich on


Description

But what if we are removing nodes

Preparation HTML

<script>
  var pole,
      body = document.body,
      template = document.createElement( 'p' ),
      slice = Array.prototype.slice;

  template.className = "removal-element";
  template.textContent = 'RemoveMe';
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
.reverse().forEach()
pole = [];
for(var i = 0; i < 500; i++) {
  body.appendChild( pole[i] = template.cloneNode( true ) );
}
console.log( 'created ' + pole.length + ' nodes' );
pole.reverse( ).forEach( function(elt) {
  elt.parentElement.removeChild(elt);
});
pole = null;
ready
.forEach()
pole = [];
for(var i = 0; i < 500; i++) {
  body.appendChild( pole[i] = template.cloneNode( true ) );
}
console.log( 'created ' + pole.length + ' nodes' );
pole.forEach( function(elt) {
  elt.parentElement.removeChild(elt);
});
pole = null;
ready

Revisions

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