Filtering Methods

JavaScript performance comparison

Test case created

Preparation code

<script src="https://github.com/documentcloud/underscore/raw/master/underscore-min.js">
</script>
<script>
Benchmark.prototype.setup = function() {
    var arrOfEl = ['jason', 'jason', 'jason', 'james', 'james', 'jason', 'james', 'johan', 'jonah', 'jason', 'james', 'james', 'james', 'john', 'johan', 'james', 'jason', 'jonah', 'jason', 'james', 'jack', 'jolly', 'jalop', 'johan', 'jonah', 'james', 'jeckyll', 'jack', 'johny', 'jockey', 'jockey', 'joke', 'joke', 'jonah', 'jason', 'james'];
   
    var len = arrOfEl.length - 1;
};

Benchmark.prototype.teardown = function() {
    arrOfEl = ['jason', 'jason', 'jason', 'james', 'james', 'jason', 'james', 'johan', 'jonah', 'jason', 'james', 'james', 'james', 'john', 'johan', 'james', 'jason', 'jonah', 'jason', 'james', 'jack', 'jolly', 'jalop', 'johan', 'jonah', 'james', 'jeckyll', 'jack', 'johny', 'jockey', 'jockey', 'joke', 'joke', 'jonah', 'jason', 'james'];
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Underscore
arrOfEl = _.uniq(arrOfEl);
pending…
Native
arrOfEl = arrOfEl.sort().filter(function(el, i, arr) {
  return (el != arr[i + 1]);
});
pending…
Loop
for(var i=0; i < len; i++) { 
        for(var j=0; j < len; j++) {
                if(arrOfEl[i] == arrOfEl[j] && i != j) { arrOfEl.splice(j,1); }
        }
}
pending…

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

Compare results of other browsers

0 comments

Add a comment