jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script>var underscore = _.noConflict();</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.compat.min.js"></script>
<script>var lodash = _.noConflict();</script>var arr = [0, 1, 2, 3, 4, 5, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
0, 1, 2, 3, 4, 0, 1, 3, 5, 0, 7, 1, 'f', 'h', 'c', 'a', 'b', 0, 1, 5
];
var arrclone1 = [0, 1, 2, 3, 4, 5, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
0, 1, 2, 3, 4, 0, 1, 3, 5, 0, 7, 1, 'f', 'h', 'c', 'a', 'b', 0, 1, 5
];
var arrclone2 = [0, 1, 2, 3, 4, 5, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
0, 1, 2, 3, 4, 0, 1, 3, 5, 0, 7, 1, 'f', 'h', 'c', 'a', 'b', 0, 1, 5
];
var arrclone3 = [0, 1, 2, 3, 4, 5, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
0, 1, 2, 3, 4, 0, 1, 3, 5, 0, 7, 1, 'f', 'h', 'c', 'a', 'b', 0, 1, 5
];
var jqFilter = function(v, k) {
return $.inArray(v, arr) === k;
}
Array.prototype.unique = function() {
var a = [];
for (var i = 0, l = this.length; i < l; i++)
if (a.indexOf(this[i]) === -1)
a.push(this[i]);
return a;
}
Array.prototype.unique2 = function() {
var a = [];
var l = this.length;
while (--l > 0) {
if (a.indexOf(this[l]) === -1)
a.push(this[l]);
}
return a;
}
Array.prototype.unique2rev = function() {
var a = [];
var l = arr.length;
while (--l > 0) {
if (a.indexOf(arr[l]) === -1)
a.push(arr[l]);
}
a.sort(function(a, b) {
return a - b
});
return a;
}
Array.prototype.getUnique = function() {
var u = {}, a = [];
for (var i = 0, l = this.length; i < l; ++i) {
if (u.hasOwnProperty(this[i])) {
continue;
}
a.push(this[i]);
u[this[i]] = 1;
}
return a;
}
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
Array.prototype.sortFilter = function() {
var sorted_arr = this.sort();
var results = [];
for (var i = 0; i < this.length - 1; i++) {
if (sorted_arr[i + 1] == sorted_arr[i]) {
results.push(sorted_arr[i]);
}
}
return results;
}
Array.prototype.sortUnique = function() {
this.sort();
var last_i;
for (var i = 0; i < this.length; i++)
if ((last_i = this.lastIndexOf(this[i])) !== i)
this.splice(i + 1, last_i - i);
return this;
}Ready to run.
| Test | Ops/sec | |
|---|---|---|
| jQuery grep | | ready |
| Underscore uniq | | ready |
| My arr.unique | | ready |
| Rafael's arr.getUnique | | ready |
| TLindig's filter | | ready |
| swilliams' sorted testing | | ready |
| My version of sorted testing | | ready |
| Sorting my arr.unique | | ready |
| Lodash uniq | | ready |
| My arr.unique while | | ready |
| My version of sorted testing + while | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.