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
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script>
function deepEqual(obj1, obj2) {
if (obj1 === obj2) {
return true
}
if (obj1 == null || obj2 == null || typeof obj1 !== 'object' || typeof obj2 !== 'object') {
return false
}
const keys1 = Object.keys(obj1)
const keys2 = Object.keys(obj2)
if (keys1.length !== keys2.length) {
return false
}
for (const key of keys1) {
if (!keys2.includes(key) || !deepEqual(obj1[key], obj2[key])) {
return false
}
}
return true
}
function generateRandomObject(objectSize, maxDepth) {
const KB = 1024;
const targetSize = objectSize * KB;
let currentSize = 0;
function getRandomKey() {
return Math.random().toString(36).substring(2, 15);
}
function getRandomPrimitive() {
const primitives = [
Math.random().toString(36).substring(2, 15), // string
Math.floor(Math.random() * 100), // number
Math.random() < 0.5, // boolean
null // null
];
return primitives[Math.floor(Math.random() * primitives.length)];
}
function getRandomValue(depth) {
if (depth >= maxDepth) {
return getRandomPrimitive();
}
const types = ['object', 'array', 'primitive'];
const type = types[Math.floor(Math.random() * types.length)];
switch (type) {
case 'object':
return generateRandomObjectHelper(depth + 1);
case 'array':
return Array.from({ length: Math.floor(Math.random() * 5) + 1 }, () => getRandomValue(depth + 1));
case 'primitive':
return getRandomPrimitive();
}
}
function generateRandomObjectHelper(depth) {
const obj = {};
while (currentSize < targetSize) {
for (let i = 0; i < 10; i++) { // Increase the number of keys per level
const key = getRandomKey();
const value = getRandomValue(depth);
obj[key] = value;
currentSize += key.length + JSON.stringify(value).length;
if (currentSize >= targetSize) break;
}
}
return obj;
}
return generateRandomObjectHelper(0);
}
var smallObj = generateRandomObject(1, 3);
var smallObj2 = generateRandomObject(1, 3);
var medObj = generateRandomObject(3, 6);
var medObj2 = generateRandomObject(3, 6);
var largeObj = generateRandomObject(5, 8);
var largeObj2 = generateRandomObject(5, 8);
Ready to run.
Test | Ops/sec | |
---|---|---|
Lodash isEqual - Small (Equal) |
| ready |
Vanilla deepEqual - Small (Equal) |
| ready |
Lodash isEqual - Medium (Equal) |
| ready |
Vanilla deepEqual - Medium (Equal) |
| ready |
Lodash isEqual - Large (Equal) |
| ready |
Vanilla deepEqual - Large (Equal) |
| ready |
Lodash isEqual - Small (Not equal) |
| ready |
Vanilla deepEqual - Small (Not equal) |
| ready |
Lodash isEqual - Medium (Not equal) |
| ready |
Vanilla deepEqual - Medium (Not equal) |
| ready |
Lodash isEqual - Large (Not equal) |
| ready |
Vanilla deepEqual - Large (Not equal) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.