notification fields

Benchmark created on


Setup

"use strict";
const notificationFields = ['foo', 'bar', 'baz', 'quux'];
const data = {
    foo: { value: true },
    bar: { value: false },
    baz: { value: true },
    quux: { value: false },
};
function getNotificationChannelCount1() {
    return notificationFields.reduce((count, fieldName) => {
        if (data[fieldName].value) {
            count += 1;
        }
        return count;
    }, 0);
}
function getNotificationChannelCount2() {
    let count = 0;
    for (const fieldName of notificationFields) {
        if (data[fieldName].value) {
            count += 1;
        }
    }
    return count;
}

function getNotificationChannelCount3() {
    let count = 0;
    for (let i = 0; i < notificationFields.length; i++) {
        if (data[notificationFields[i]].value) {
            count += 1;
        }
    }
    return count;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Reduce
getNotificationChannelCount1();
ready
for-of
getNotificationChannelCount2();
ready
for i
getNotificationChannelCount3();
ready

Revisions

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