arrays methods vs iterator methods (v7)

Revision 7 of this benchmark created on


Description

creating N (50) items, apply trivial calculations and display results (in order make sure no code gets dead-code-eliminated).

Test runner

Ready to run.

Testing in
TestOps/sec
array methods
var numbers = Array.from({length: 500}, (v, i) => i)
numbers
  .map(x => x+1)
  .map(x => x*2)
  .map(x => x-1)
  .map(x => x/2)
  .forEach(x => console.log(x))
ready
iterators
var numbers = Array.from({length: 500}, (v, i) => i)
function * map(mapperFn, iterable){
  for (const item of iterable){
  	yield mapperFn(item)
  }	
}
numbers = map(x => x+1, numbers)
numbers = map(x => x*2, numbers)
numbers = map(x => x-1, numbers)
numbers = map(x => x/2, numbers)
for (const item of numbers){
	console.log(item)
}	
ready

Revisions

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