Compare Filter+Map to For-Loop

Benchmark created on


Setup

const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

Test runner

Ready to run.

Testing in
TestOps/sec
Filter + Map
const newArray = array.filter(x => x % 2 === 0).map(x => 2 * x);


ready
For-Loop doing the same thing
const newArray = [];
for (let i = 0; i < array.length; i++) {
	if (array[i] % 2 === 0) {
		newArray.push(array[i]);
	}
}
ready

Revisions

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