Uniq (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script>
  var array = [0, 1, 20, 5, 6, 20, 3, 0, 2, 5, 0, 5, 2, 23, 0, 2, 0, 12, 3, 2, 0, 255];
  
  function uniqFor(array) {
    var i, j;
    for (i = 0; i < array.length; i += 1) {
      for (j = i + 1; j < array.length; j += 1) {
        if (array[i] === array[j]) {
          array.splice(j, 1);
          j -= 1;
        }
      }
    }
  }
  
  function uniqFilter(array) {
    return array.filter(function(value, i) {
      return array.indexOf(value, i + 1) === -1;
    });
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
For
var result = array.slice();
uniqFor(result);
ready
Filter
var result = uniqFilter(array);
ready
Filter inplace
var result = uniqFilter(array.slice());
ready

Revisions

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