Native map vs. forEach appending vs. array looping (v14)

Revision 14 of this benchmark created on


Preparation HTML

<script>
  var g = [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];
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Map (native)
var h = g.map(function(x) {
  return x + 2
});
ready
forEach (native)
var h = [];
g.forEach(function(x) {
  h.push(x + 2);
})
ready
Loop
var forEa = (function(array, action) {
  for (var i = 0; i < array.length; i++)
    action(array[i]);
})();

var h = [];
forEach(g, function(x) {
  h.push(x + 2);
});
ready

Revisions

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