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
function splitAndResolveFast(role, template) {
let roles;
if (typeof role === 'string') {
roles = role.split(/[,\s]+/);
} else if (Array.isArray(role)) {
roles = role;
} else {
return role;
}
for (let i = 0; i < roles.length; ++i) {
roles[i] = roles[i];
}
return roles;
}String.customSplit = function(str, delim) {
const ret = [];
let foundIdx = str.indexOf(delim);
if (foundIdx !== -1) {
let retIdx = 0, lastIdx = 0;
do {
ret[retIdx++] = str.substring(lastIdx, foundIdx);
lastIdx = foundIdx + delim.length;
foundIdx = str.indexOf(delim, lastIdx);
} while(foundIdx !== -1);
if (lastIdx <= str.length) {
ret[retIdx] = str.substring(lastIdx);
}
// ret.length = retIdx;
} else {
ret[0] = str;
// ret.length = 1;
}
return ret;
};
String.isString = function(value) {
// Nothing except a String should have both of these prototypes
// This is untrue: TemplateInstance can have both functions. The line below has been replaced with a different approach.
// return !!(value != null && value.substring && value.substr);
return typeof value === 'string' || value instanceof String;
// More Proper way to do this would be
// return Object.prototype.toString.call(object) === "[object String]";
// But this is significatantly slower on pretty much everything except "Chrome"
};
function splitAndResolveSlow(role, template) {
//var type = kindOf(role);
var roles;
//if(type === 'string') roles = role.split(/(?:\s*,\s*)|(?:\s+)/);
//else if(type === 'array') roles = role;
if(String.isString(role)) roles = role.split(/(?:\s*,\s*)|(?:\s+)/);
else if(Array.isArray(role)) roles = role;
else return role;
for(var i = roles.length - 1;i >= 0;i--) {
roles[i] = roles[i];
}
return roles;
}
function splitAndResolveFastest(role, template) {
let roles;
if (typeof role === 'string') {
roles = role.split(/[, ]+/);
} else if (Array.isArray(role)) {
roles = role;
} else {
return role;
}
for (let i = 0; i < roles.length; ++i) {
roles[i] = roles[i];
}
return roles;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Slow |
| ready |
Fast? |
| ready |
Fastest? |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.