jQuery.unique VS _.uniq Performance

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.0.1/lodash.min.js"></script>
<script>
var lodash = _.noConflict();

function uniq(a) {
  var v = [], x = undefined;
  a.sort().forEach(function(n) {
    if(n != x) {
      v.push(x = n);
    }
  });
  return v;
}

</script>
<script>
Benchmark.prototype.setup = function() {
    var $ = window.$;
    var _ = window._;
    var lodash = window.lodash;
    var myArr = [1, 2, 1, 3, 1, 4];
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
jQuery
var result = $.unique( myArr );
pending…
Underscore
var result = _.uniq( myArr );
pending…
Lo-Dash
var result = lodash.uniq( myArr );
pending…
Own
var result = uniq( myArr );
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment