objectsEqual
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
const objectsEqualA = (objA, objB) => JSON.stringify(objA) === JSON.stringify(objB);
const objectsEqualB = (objA, objB) => {
const objAKeys = Object.keys(objA).sort();
const objBKeys = Object.keys(objB).sort();
if (objAKeys.length !== objBKeys.length) {
return false;
}
for (let i = 0; i < objAKeys.length; i++) {
if (objAKeys[i] !== objBKeys[i]) {
return false;
}
const key = objAKeys[i];
if (objA[key] !== objB[key]) {
return false;
}
}
return true;
};
const o1 = {ameise: 'hallo', banane: 'welt', 'chameleon-drama': 'bla'};
const o2 = {nest: 'vogel', was: 'auch immer'};
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Test | Ops/sec | |
---|---|---|
Test method A (JSON.stringify)
|
|
pending… |
Test method B (functional approach))
|
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit
to the URL.
- Revision 1: published Paratron
- Revision 2: published Christian Engel
- Revision 3: published Christian Engel
- Revision 4: published Christian Engel
0 Comments