map vs for

Benchmark created on


Description

comparing array modification

Preparation HTML

<script type="text/javascript">
var testArray = [];
var i = 1000;
while (i) {
  var obj = {
    id: i,
    name: 'test text '+i
  };
  testArray.push(obj);
  i--;
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
map
testArray.map(function(el) {
  el.extended = el.name + ' _ext';
  return el;
});
ready
for
for (var i = 0; i < testArray.length; i++) {
  var el = testArray[i];
  el.extended = el.name + ' _ext';
}
ready

Revisions

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