function-performance-test
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

function-performance-test

Tests the performance of given functions returning averageTime, lowestTime and highestTime.

How to use

import { performanceTest } from 'function-performance-test';

// Dummy test functions
function test(a, b) {
    return a + b;
}

function test1(a, b) {
    return a + b;
}

// Single function test
const testSubject1 = { 
    fn: test, 
    args: [2, 'a'], 
    options: { 
        iterations: 5,
    } 
};

const pt1 = performanceTest(testSubject1);
const result1 = pt1.run();

// result1
// [
//     {
//         functionName: 'test',
//         iterationsRun: 5,
//         averageTime: 0.0187,
//         lowestTime: 0.0081,
//         highestTime: 0.0575
//     }
// ]


// Multiple function test
const testSubject2 = [
    { fn: test, args: [3, 'b'], options: { iterations: 3 } },
    { fn: test1, args: [4, 'c'], options: { iterations: 4 } }
];

const pt2 = performanceTest(testSubject2);
const result2 = pt2.run();

// result2
// [
//     {
//         functionName: 'test',
//         iterationsRun: 3,
//         averageTime: 0.0102,
//         lowestTime: 0.0087,
//         highestTime: 0.0125
//     },
//     {
//         functionName: 'test1',
//         iterationsRun: 4,
//         averageTime: 0.0119,
//         lowestTime: 0.0087,
//         highestTime: 0.0132
//     }
// ]

Interfaces

interface Options {
    iterations?: number;
}

export interface TestSubject {
    fn: Function;
    args?: Array<any>;
    options?: Options;
}

export interface TestResult {
    functionName: string;
    iterationsRun: number;
    averageTime: number;
    lowestTime: number;
    highestTime: number;
}

Dependencies (0)

    Dev Dependencies (5)

    Package Sidebar

    Install

    npm i function-performance-test

    Weekly Downloads

    1

    Version

    1.0.6

    License

    ISC

    Unpacked Size

    6.01 kB

    Total Files

    8

    Last publish

    Collaborators

    • sraxi87