jQuery.unique VS _.uniq Performance
JavaScript performance comparison
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>
Benchmark.prototype.setup = function() {
var $ = window.$;
var _ = window._;
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.
| Test | Ops/sec | |
|---|---|---|
jQuery |
|
pending… |
Underscore |
|
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:
- Revision 1: published by EtnasSoft and last updated
- Revision 2: published
1 comment
Kind of like comparing apples to bacon, isn't it? The jQuery documentation states:
(emphasis mine)
And then if one dived into the code, one could see that
unique, like some of the stuff in jQuery, is simply wrongly named and does actually something very different.jQuery.uniqueis actually all about sorting. About sorting in document order. And then also, as an additional service, removing duplicates.