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
const stylesObject = {
foo: 'foo',
bar: 'bar',
baz: null,
color: undefined
}
function stylesStringEntries(styles) {
if (!styles || typeof styles !== 'object') return '';
return Object.entries(styles)
.filter(([key, value]) => !!value)
.map(([key, value]) => {
return `${key}:${value};`;
})
.join('');
}
function stylesStringForIn(styles) {
if (!styles || typeof styles !== 'object') return '';
let result = '';
for (let key in styles) {
if (styles[key]) {
result += key + ':' + styles[key] + ';';
}
}
return result;
}
function stylesStringReduce(styles) {
if (!styles || typeof styles !== 'object') return '';
return Object.keys(styles).reduce((str, key) => {
const value = styles[key];
if (value) {
return str + `${key}:${value};`;
} else {
return str
}
}, '');
}
Ready to run.
| Test | Ops/sec | |
|---|---|---|
| Object.entries | | ready |
| ForIn | | ready |
| Object.keys().Reduce | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.