get Range

Benchmark created on


Setup

function getRange(startFrom, until) {
  const result = [];
  for (let i = startFrom; i <= until; i++) {
    result.push(i);
  }
  return result;
}

function getRangeNew(startFrom, until) {
  const result = new Array(until - startFrom + 1);
  for (let i = startFrom; i <= until; i++) {
    result[i - startFrom] = i;
  }
  return result;
}

function arrayFrom(startFrom, until) {
	return Array.from({ length: until + 1 - startFrom }, (_, k) => k + startFrom);
}

Test runner

Ready to run.

Testing in
TestOps/sec
empty array
getRange(0, 10)
ready
New
getRangeNew(0, 10)
ready
array from
arrayFrom(0, 10)
ready

Revisions

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