map vs for-loop (v6)

Revision 6 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
map
const arr = [
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
  22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
]
const result = arr.map((item) => item)
ready
for-loop
const arr = [
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
  22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
]
const result = []
for (let i = 0; i < arr.length; i++) {
  result.push(arr[i]);
}
ready
for-loop cached array length
const arr = [
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
  22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
]
const result = []
const len = arr.length;
for (let i = 0; i < len; i++) {
  result.push(arr[i]);
}
ready
for-loop fixed array length
const arr = [
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
  22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
]

const len = arr.length;
const result = new Array(len);
for (let i = 0; i < len; i++) {
  result[i] = arr[i];
}
ready

Revisions

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