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 src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></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.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;
}
Array.prototype.getUnique2 = function(){
var u = Object.create(null), a = [];
for(var i = 0, l = this.length; i < l; ++i){
if(u[i]) {
continue;
}
a.push(this[i]);
u[this[i]] = 1;
}
return a;
}
Array.prototype.getUnique3 = function(){
var u = Object.create(null), a = [];
for(var i = 0, l = this.length; i < l; ++i){
if(i in u) {
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 |
arr.getUnique2 |
| ready |
arr.getUnique3 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.