Filter vs for

Benchmark created on


Setup

arraySize = 100

Test runner

Ready to run.

Testing in
TestOps/sec
Filter
array = Array.from({length: arraySize}, () => Math.random());

res = array.filter(v => v > 0.5)

if (res.length > 0)
	res = []
ready
For
array = Array.from({length: arraySize}, () => Math.random());

res = []

for (let v of array)
 v > 0.5 && res.push(v);
 
 if (res.length > 0)
	res = []
ready

Revisions

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