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
Check to see what's the fastest isEmpty method.
<script>
var a = {};
var b = {
one: 1,
two: 2,
three: "3"
};
// original
function isEmpty(obj) {
for (var key in obj) {
return false;
}
return true;
}
// only in newer browsers
function isEmpty2(obj) {
return ( !! Object.keys(obj).length);
}
// only in Firefox
function isEmpty3(obj) {
return !obj.toSource()[4];
}
// only in Firefox
function isEmpty4(obj) {
return obj.toSource() === '({})';
}
// only in newer browsers
function isEmpty5(obj) {
return !Object.getOwnPropertyNames(obj)[0];
}
// only in newer browsers
function isEmpty6(obj) {
return !Object.getOwnPropertyNames(obj).length;
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
isEmpty original - a |
| ready |
isEmpty original - b |
| ready |
isEmpty2 - a |
| ready |
isEmpty2 - b |
| ready |
isEmpty3 - a |
| ready |
isEmpty3 - b |
| ready |
isEmpty4 - a |
| ready |
isEmpty4 - b |
| ready |
isEmpty5 - a |
| ready |
isEmpty5 - b |
| ready |
isEmpty6 - a |
| ready |
isEmpty6 - b |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.