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
This test evaluates the performance of the findPopoverMenu function with a large dataset.
// Generate a large dataset
function generateLargeDataset(depth, breadth) {
function createItem(id, level) {
return {
id: id,
has_popover: true,
sub_items: level > 0 ? new Array(breadth).fill(0).map((_, index) => createItem(`${id}-${index}`, level - 1)) : []
};
}
return createItem('root', depth);
}
const largeDataset = generateLargeDataset(4, 10); // Adjust depth and breadth for size
const searchId = 'root-3-2-4'; // Example ID to search
// Define findPopoverMenu function
export function findPopoverMenu(item, id) {
const result = { popOverMenu: '', parent_id: '', expanded: false };
function matchItem(item, parentId = '') {
if (item.has_popover) {
if (item.id === id) {
result.popOverMenu = item;
result.parent_id = parentId;
result.expanded = true;
return true; // Found the item, exit early
}
if (item.sub_items && item.sub_items.length > 0) {
for (const subItem of item.sub_items) {
if (matchItem(subItem, item.id)) {
return true; // Exit early if item is found
}
}
}
}
return false; // Continue search if item not found
}
matchItem(item);
return result;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Test findPopoverMenu Performance |
| ready |
Test findPopoverMenu Performance with larger dataset |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.