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
/*
## ##### Copyright (c) - Kevin McGinty
# _ # ###
# # # AtomicFrameworks
*/
/*jslint plusplus: true */
(function(globals){
"use strict";
var mappers;
globals.mappers = mappers = {
obj: function (collection, callback, thisArg) {
if (typeof callback !== "function") {
throw new TypeError(callback + " is not a function");
}
var key, ret = {};
for (key in collection) {
if (collection.hasOwnProperty(key)) {
ret[key] = callback.call(thisArg, collection[key], key, collection);
}
}
return ret;
},
arr: function (collection, callback, thisArg) {
if (typeof callback !== "function") {
throw new TypeError(callback + " is not a function");
}
var i = 0, len = collection.length, ret = [];
while (i < len) {
ret[i] = callback.call(thisArg, collection[i], i, collection);
++i;
}
return ret;
},
deep: function (collection, callback, thisArg) {
var ret, i, len;
if (typeof callback !== "function") {
throw new TypeError(callback + " is not a function");
}
// Map object by key
if (collection.toString() === '[object Object]') {
ret = {};
for (i in collection) {
if (collection.hasOwnProperty(i)) {
// Recurse any objects (this includes arrays)
if (typeof collection[i] === "object") {
ret[i] = mappers.deep(collection[i], callback, thisArg);
} else {
ret[i] = callback.call(thisArg, collection[i], i, collection);
}
}
}
} else {
// Else map string and array to array by index
// IE 7 cannot iterate over strings
if (typeof collection === "string") {
collection = collection.split('');
}
i = 0;
len = collection.length;
ret = [];
while (i < len) {
if (typeof collection[i] === "object") {
ret[i] = mappers.deep(collection[i], callback, thisArg);
} else {
ret[i] = callback.call(thisArg, collection[i], i, collection);
}
++i;
}
}
return ret;
}
};
// Extend array with map if not native
// Syntax - array.map(callback[, thisArg]);
if (!Array.prototype.map) {
Array.prototype.map = function (callback, thisArg) {
return mappers.arr(this, callback, thisArg);
};
}
// Extend object with map if not native
// Syntax - array.map(callback[, thisArg]);
if (!Object.prototype.map) {
Object.prototype.map = function (callback, thisArg) {
return mappers.obj(this, callback, thisArg);
};
}
// Extend Object with mapDeep
// Syntax - array.map(callback[, thisArg]);
if (!Object.prototype.mapDeep) {
Object.prototype.mapDeep = function (callback, thisArg) {
return mappers.deep(this, callback, thisArg);
};
}
// Extend Array with mapDeep
// Syntax - array.map(callback[, thisArg]);
if (!Array.prototype.mapDeep) {
Array.prototype.mapDeep = function (callback, thisArg) {
return mappers.deep(this, callback, thisArg);
};
}
}(this));
/*
## ##### Copyright (c) - Kevin McGinty
# _ # ###
# # # AtomicFrameworks
*/
/*jslint plusplus: true */
(function(globals){
"use strict";
globals.mappersTwo = {
obj: function (collection, callback, thisArg) {
if (typeof callback !== "function") {
throw new TypeError(callback + " is not a function");
}
var key, ret = {};
for (key in collection) {
if (collection.hasOwnProperty(key)) {
ret[key] = callback.call(thisArg, collection[key], key, collection);
}
}
return ret;
},
arr: function (collection, callback, thisArg) {
if (typeof callback !== "function") {
throw new TypeError(callback + " is not a function");
}
var i = 0, len = collection.length, ret = [];
while (i < len) {
ret[i] = callback.call(thisArg, collection[i], i, collection);
++i;
}
return ret;
},
deep: function (collection, callback, thisArg) {
var ret, i, len;
if (typeof callback !== "function") {
throw new TypeError(callback + " is not a function");
}
// Map object by key
if (collection.toString() === '[object Object]') {
ret = {};
for (i in collection) {
if (collection.hasOwnProperty(i)) {
// Recurse any objects (this includes arrays)
if (typeof collection[i] === "object") {
ret[i] = globals.mappersTwo.deep(collection[i], callback, thisArg);
} else {
ret[i] = callback.call(thisArg, collection[i], i, collection);
}
}
}
} else {
// Else map string and array to array by index
// IE 7 cannot iterate over strings
if (typeof collection === "string") {
collection = collection.split('');
}
i = 0;
len = collection.length;
ret = [];
while (i < len) {
if (typeof collection[i] === "object") {
ret[i] = globals.mappersTwo.deep(collection[i], callback, thisArg);
} else {
ret[i] = callback.call(thisArg, collection[i], i, collection);
}
++i;
}
}
return ret;
}
};
// Extend array with map if not native
// Syntax - array.map(callback[, thisArg]);
if (!Array.prototype.map) {
Array.prototype.map = function (callback, thisArg) {
return globals.mappers.arr(this, callback, thisArg);
};
}
// Extend object with map if not native
// Syntax - array.map(callback[, thisArg]);
if (!Object.prototype.map) {
Object.prototype.map = function (callback, thisArg) {
return globals.mappers.obj(this, callback, thisArg);
};
}
// Extend Object with mapDeep
// Syntax - array.map(callback[, thisArg]);
if (!Object.prototype.mapDeepTwo) {
Object.prototype.mapDeepTwo = function (callback, thisArg) {
return globals.mappersTwo.deep(this, callback, thisArg);
};
}
// Extend Array with mapDeep
// Syntax - array.map(callback[, thisArg]);
if (!Array.prototype.mapDeep) {
Array.prototype.mapDeep = function (callback, thisArg) {
return globals.mappers.deep(this, callback, thisArg);
};
}
}(this));
Ready to run.
Test | Ops/sec | |
---|---|---|
1 |
| ready |
2 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.