1.0.3 • Published 1 year ago

time-exec v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Time-exec

Checks the execution time of functions.

Installing

npm install time-exec

Start - finish

We can check the execution time of any code from calling the start method to calling the finish method.

import { Timer } from 'time-exec';

function sum(first, last) {
    let sum = 0;
    for (let i = first; i < last; i++) {
        sum += i
    }
    return sum;
}

let timer = new Timer();
timer.start();
sum(1, 10000);
timer.finish();
console.log("The function sum was completed in " + timer.getTimeExec() + "ms")

If you have started timer and haven`t finish, then getTimeExec() returns 0.

Asynchronous functions

Start-finish works with asynchronous functions.

import { Timer } from 'time-exec';

let timer = new Timer();
timer.start();
setTimeout(() => { 
    sum(1, 10000);
    timer.finish() }, 1000);
setTimeout(() => { 
    console.log("The function with timeout was completed in " + timer.getTimeExec() + "ms") 
    }, 2000);

Check the execution time of the function.

We can check the execution time of the function.

import { Timer } from 'time-exec';

let timer = new Timer();
timer.funcTimeExec(sum, 1, 10000);
console.log("The function sum was completed in " + timer.getTimeExec() + "ms");

Check the execution time of several function calls.

We can check the execution time of several function calls.

import { Timer } from 'time-exec';

let timer = new Timer();
timer.funcRepeatTimeExec(sum, 100, 1, 10000);
console.log("The function sum was completed 100 times in " + timer.getTimeExec() + "ms");

Check the average execution time of a function over several calls.

We can check the average execution time of a function over several calls.

let timer = new Timer();
timer.funcAverageTimeExec(sum, 100, 1, 10000);
console.log("For 100 times, the function was completed in an average of " + timer.getTimeExec() + "ms");

Documentation

You can find documentation in ./node_modules/time-exec/docs You can delete documentation for save memory.

System requirements

I have tested this package only: 1. Google chrome 109.0.5414.168 2. node js 20.12.2

I think that may be errors on some old node versions.

License

MIT

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago