easy-performance-measure
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

easy-performance-measure

Tiny helper package without dependencies to measure the performance of methods.

How to use

import {measureSync, measureAsync} from 'easy-performance-measure';

const syncFn = (a:string, b:number) : string=> `${a}: ${b}`;
const asyncFn = async (a:string, b:number) : Promise<string> => {
    return new Promise((resolve)=>{
        setTimeout(()=>{
            resolve(result(a, b));
        }, 250);
    });
};

const main = async () : Promise<void>=>{
    // Example for synchronous method
    const resultSync: [string, number] = measureSync<string, [string, number]>(syncFn, 'First', 5);
    console.log(resultSync); // Output: [ 'First: 5', 0 ]

    // Example for asynchronous method
    const resultAsync: [string, number] = await measureAsync<string, [string, number]>(asyncFn, 'First', 5);
    console.log(resultAsync); // Output: [ 'First: 5', 255 ]
};

main();


Readme

Keywords

Package Sidebar

Install

npm i easy-performance-measure

Weekly Downloads

1

Version

1.0.2

License

ISC

Unpacked Size

11.4 kB

Total Files

9

Last publish

Collaborators

  • pzwik