Coffeescript for loop speed comparison

Benchmark created by Nathanael on


Description

http://stackoverflow.com/questions/7538590/which-is-better-more-efficient-in-coffeescript-when-running-a-for-loop

Preparation HTML

<script>
  var iterIndices, iterString;
  iterIndices = function(str) {
    var i, s, _ref;
    s = 0;
    for (i = 0, _ref = str.length; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) {
      s += str.charCodeAt(i);
    }
    return s;
  };
  iterString = function(str) {
    var i, s, _i, _len;
    s = 0;
    for (_i = 0, _len = str.length; _i < _len; _i++) {
      i = str[_i];
      s += i.charCodeAt(0);
    }
    return s;
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Iterate indices
iterIndices('a really not very interesting string');
ready
Iterate string
iterString('a really not very interesting string');
ready

Revisions

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

  • Revision 1: published by Nathanael on