filter foreach vs one foreach

Benchmark created on


Setup

var array = [];
  for (var i = 0; i < 1000000; i++) {
      array.push(i);
  }

Test runner

Ready to run.

Testing in
TestOps/sec
foreach + filter
arr
.filter(function(element, index, array) {
  element%2 === 0;
});
.forEach(function(element, index, array) {
  var b = element;
});
ready
foreach inline filter
arr
.forEach(function(element, index, array) {
	if(element%2 === 0) {
  var b = element;		
	}

});
ready

Revisions

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