coffee for loops

Benchmark created by clux on


Preparation HTML

<script>
  Array.prototype.uniqueCoffee = function() {
    var i, j, l, _results;
    l = this.length;
    _results = [];
    for (i = 0; 0 <= l ? i <= l : i >= l; 0 <= l ? i++ : i--) {
      for (j = 0; 0 <= l ? j <= l : j >= l; 0 <= l ? j++ : j--) {
        if (this.i === this.j) {
          j = ++i;
        }
      }
      _results.push(this[i]);
    }
    return _results;
  };
  
  Array.prototype.unique = function() {
    var a = [];
    var l = this.length;
    for(var i=0; i<l; i++) {
      for(var j=i+1; j<l; j++) {
        // If this[i] is found later in the array
        if (this[i] === this[j])
          j = ++i;
      }
      a.push(this[i]);
    }
    return a;
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
coffee
[5,4,3,2,1,6,7,8,9,4,5,6,7,1,11,21,13,22,11,5].uniqueCoffee();
ready
normal
[5,4,3,2,1,6,7,8,9,4,5,6,7,1,11,21,13,22,11,5].unique();
ready

Revisions

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