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
Test for Overrides
function getOverrides(id, condValue, object) {
let startTime = performance.now();
let result = {};
let workObj = typeof (object) === 'string' ? JSON.parse(object) : object;
if (workObj.hasOwnProperty(condValue)) {
// Check, if Property exists - if yes, directly return it, because thats the best match
result = workObj[condValue];
} else {
// Property not found. We need to check the values!
const operators = new RegExp('[=><!]');
let tmpObj = Object.keys(workObj)
.sort(
(a, b) => a.toLowerCase().localeCompare(b.toLowerCase(), undefined, { numeric: true, sensitivity: 'base' }))
.reduce(
(obj, key) => {
// Check, if we have a condition inside the object
if (operators.test(key)) {
// Now, we need to check, if condValue is a number
if (!isNaN(condValue)) {
// Operator found - check for condition
try {
const func = Function(`return ${condValue}${key}`)();
if (func) {
result = workObj[key];
}
}
catch (func) {
console.log(`Overrides for element ${id} can not be processed, as they are not correctly formatted! ${func} For: ${key}`);
}
}
}
return obj;
},
{}
);
}
if (Object.keys(result).length == 0) {
// Check, if we have a fallback for it
if (workObj.hasOwnProperty('default')) {
result = workObj['default'];
}
}
// Process the result values, if available
if (Object.keys(result).length > 0) {
// Value
if (result.hasOwnProperty('value')) {
try {
const func = new Function(`return ${result['value']}`)();
result['value'] = func(condValue);
}
catch (func) {
console.log(`Value-Overrides for element ${id} can not be processed, as they are not correctly formatted! Error: ${func} Supplied function: ${result['value']}`);
result['value'] = 0;
}
}
// Unit
if (result.hasOwnProperty('unit')) {
try {
const func = Function(`return ${result['unit']}`)();
result['unit'] = func(condValue);
}
catch (func) {
console.log(`Unit-Overrides for element ${id} can not be processed, as they are not correctly formatted! Error: ${func} Supplied function: ${result['unit']}`);
result['unit'] = '';
}
}
}
let endTime = performance.now();
console.log(`${Object.keys(object).length} Elements checking took ${endTime - startTime} ms`);
return result;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Testing the code |
| ready |
Testing the code 2 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.