fill then map vs array.from vs generator (v5)

Revision 5 of this benchmark created on


Setup

function* range(start, end) {
  for (var i = start; i <= end; i++) {
    yield i;
  }
}

function rangearr(start,end) {
  const result = [];
  for (var i = start; i <= end; i++) {
    result.push(i);
  }	
  return i;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Fill then map
new Array(100).fill('').map((_, i) => {
	return i + i;
})
ready
array.from
Array.from({length: 100}).map((_, i) => {
	return i + i;
})
ready
Second arg map function
Array.from({length: 100}, (_, i) => {
	return i + i;
})
ready
Array.from with generator
Array.from(range(1,100))
ready
Helper function
rangearr(1,100)
ready

Revisions

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