engine icon indicating copy to clipboard operation
engine copied to clipboard

fix: return measured result

Open Ari-Kishon opened this issue 4 years ago • 0 comments

A minor change to cross-performance.

returns the result a measurement. updated the d.ts file accordingly

this is a none breaking change since the original return type was void.

would be useful in the following situation

import performance from '@wixc3/cross-performance';

export const measure = async <T extends (...args: any[]) => any>(label: string, method: T) => {
    const startLabel = `startMeasure: ${label}`;
    const endLabel = `endMeasure: ${label}`;
    performance.mark(startLabel);
    const result = await method();
    performance.mark(endLabel);
    return {
        result,
        measurement: performance.measure(label, startLabel, endLabel),
    };
};

        const {
            result,
            measurement: { name, duration },
        } = await measure(label, method);

Ari-Kishon avatar Apr 05 '22 21:04 Ari-Kishon