Coffeescript for comprehension vs .map

Benchmark created by Tim Ruffles on


Preparation HTML

<script>
  var items, mapped;
  items = [
    {
      foo: "bar"
    }, {
      foo: "bar"
    }, {
      foo: "bar"
    }, {
      foo: "bar"
    }, {
      foo: "bar"
    }
  ];
  
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Array#map
mapped = items.map(function(item) {
  return item.foo;
});
ready
Coffeescript comprehension
csMapped = (function() {
  var _i, _len, _results;
  _results = [];
  for (_i = 0, _len = items.length; _i < _len; _i++) {
    item = items[_i];
    _results.push(item.foo);
  }
  return _results;
})();
ready

Revisions

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

  • Revision 1: published by Tim Ruffles on