for vs. forEach (v2)

Revision 2 of this benchmark created on


Setup

const notifications = [
    {
        1: {
            abortController: new AbortController(),
            aninmationDuration: 500,
            dismissable: true,
            state: "WAIT_ON_HIDE",
            text: "This instance allows at most a single, sticky notification to be shown.",
            title: undefined,
            type: "default",
            visibleTimeMs: 60000,
        },
        2: {
            abortController: new AbortController(),
            aninmationDuration: 500,
            dismissable: true,
            state: "WAIT_ON_HIDE",
            text: "This instance allows at most a single, sticky notification to be shown.",
            title: undefined,
            type: "default",
            visibleTimeMs: 60000,
        },
        3: {
            abortController: new AbortController(),
            aninmationDuration: 500,
            dismissable: true,
            state: "SHOWING",
            text: "This instance allows at most a single, sticky notification to be shown.",
            title: undefined,
            type: "default",
            visibleTimeMs: 60000,
        },
        4: {
            abortController: new AbortController(),
            aninmationDuration: 500,
            dismissable: true,
            state: "SHOWING",
            text: "This instance allows at most a single, sticky notification to be shown.",
            title: undefined,
            type: "default",
            visibleTimeMs: 60000,
        },
        5: {
            abortController: new AbortController(),
            aninmationDuration: 500,
            dismissable: true,
            state: "HIDING",
            text: "This instance allows at most a single, sticky notification to be shown.",
            title: undefined,
            type: "default",
            visibleTimeMs: 60000,
        },
        41: {
            abortController: new AbortController(),
            aninmationDuration: 500,
            dismissable: true,
            state: "SHOWING",
            text: "This instance allows at most a single, sticky notification to be shown.",
            title: undefined,
            type: "default",
            visibleTimeMs: 60000,
        },
        10: {
            abortController: new AbortController(),
            aninmationDuration: 500,
            dismissable: true,
            state: "WAIT_ON_HIDE",
            text: "This instance allows at most a single, sticky notification to be shown.",
            title: undefined,
            type: "default",
            visibleTimeMs: 60000,
        },
        21: {
            abortController: new AbortController(),
            aninmationDuration: 500,
            dismissable: true,
            state: "WAIT_ON_HIDE",
            text: "This instance allows at most a single, sticky notification to be shown.",
            title: undefined,
            type: "default",
            visibleTimeMs: 60000,
        },
        51: {
            abortController: new AbortController(),
            aninmationDuration: 500,
            dismissable: true,
            state: "HIDING",
            text: "This instance allows at most a single, sticky notification to be shown.",
            title: undefined,
            type: "default",
            visibleTimeMs: 60000,
        },
        31: {
            abortController: new AbortController(),
            aninmationDuration: 500,
            dismissable: true,
            state: "SHOWING",
            text: "This instance allows at most a single, sticky notification to be shown.",
            title: undefined,
            type: "default",
            visibleTimeMs: 60000,
        },
    },
];

Test runner

Ready to run.

Testing in
TestOps/sec
for
function hideScheduledNotificationIds() {
    const matches = [];
    for (const notificationId in notifications) {
        if (notifications[notificationId].state === "WAIT_ON_HIDE") {
            matches.push(notificationId);
        }
    }
    return matches;
}
ready
forEach
function hideScheduledNotificationIds() {
    const matches = [];
    Object.entries(notifications).forEach((notification) => {
        if (notification[1].state === "WAIT_ON_HIDE") {
            matches.push(notification[0]);
        }
    });
    return matches;
}
ready

Revisions

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