Create findPopoverMenu performance test (v2)

Revision 2 of this benchmark created on


Description

This test evaluates the performance of the findPopoverMenu function with a large dataset.

Preparation HTML


Setup

// 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
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;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Test findPopoverMenu Performance
findPopoverMenu(largeDataset, searchId);
ready
Test findPopoverMenu Performance with larger dataset
// Generate an even larger dataset
const largerDataset = generateLargeDataset(5, 15); // Increase depth and breadth
const largerSearchId = 'root-10-5-10'; // Example ID to search in the larger dataset

findPopoverMenu(largerDataset, largerSearchId);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.