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
Ways of counting the number of properties in an object (added precomputed baseline - SBD)
function generateObjects(lengths) {
var objects = []
for (var i = 0; i < lengths.length; i++) {
var obj = {};
var len = lengths[i];
for (var j = 0; j < len; j++) {obj[i + "-" + j] = i * len + j; }
obj.len = len;
objects.push(obj);
}
return objects;
}
var largeObjects = generateObjects([326, 140, 688, 128, 582, 416, 278, 803, 845]);
var smallObjects = generateObjects([3, 1, 6, 2, 5, 4, 2, 8, 8]);
function objectLengthCount(object) {
var length = 0;
for (var key in object) {++length;}
return length;
}
function objectLengthCount1(object) {
for (var key in object) {return true;}
return false;
}
function objectLengthCountHasOwnProperty(object) {
var length = 0;
for (var key in object) {
if (object.hasOwnProperty(key)) ++length;
}
return length;
}
function objectLengthCountHasOwnProperty1(object) {
for (var key in object) {
if (object.hasOwnProperty(key)) return true;
}
return false;
}
function objectLengthKeys(object) {
return Object.keys(object).length;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
largeObjects: Object.keys |
| ready |
largeObjects: counting |
| ready |
largeObjects: precomputed |
| ready |
largeObjects: count to 1 |
| ready |
smallObjects: Object.keys |
| ready |
smallObjects: counting |
| ready |
smallObjects: count to 1 |
| ready |
largeObjects: counting with hasOwnProperty |
| ready |
smallObjects: counting with hasOwnProperty |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.