benchscript v0.2.3
Benchmark for functions written on typescript
A console application based on NodeJs.
This is a minimal console application for benchmarking your functions on NodeJS application written in TypeScript or JS. Application calculates time to run a function, cpu usage, and ram usage.
Use this app along with NodeJS and TypeScript. NodeJs TypeScript
A basic Benchmark application needs just few files to run and test your code:
package.json
- Points to the app's main file and lists its details and dependencies.tsconfig.json
- Has all configurations needed for TypeScript file to compile properly.
To Use
To install this package you need to run command bellow
npm i benchscript
Note: If you're using Linux Bash for Windows, see this guide or use node
from the command prompt.
Using CLI
For using benchmark on your function you need to go through few steps:
- Create a TypeScript file containing your test functions as below:
export const testFunctions = [
{
title: "SampleTitle1",
fn: function YourFunction1() {
//Does something
},
},
{
title: "SampleTitle2",
fn: function YourFunction2() {
//Does something
},
},
{
title: "SampleTitle3",
fn: function YourFunction3() {
//Does something
},
},
];
- Or create a JavaScript file containing your test functions as below:
Object.defineProperty(exports, "__esModule", { value: true });
exports.testFunctions = [
{
title: "SampleTitle1",
fn: function YourFunction1() {
//Does something
},
},
{
title: "SampleTitle2",
fn: function YourFunction3() {
//Does something
},
},
{
title: "SampleTitle3",
fn: function YourFunction3() {
//Does something
},
},
];
Save your file and copy it`s path
Run bash command and put you file path into it
Give number of iterations(number of how many times each function needed to be called on each run)
- Give number of runs(number of runs for calculating average results after dumping)
bench --path /YourTestFilePath --iterations "-number of iterations" --runs "-number of runs"
- Get results:
┌───────────────┬───────────────────┬──────────┬───────────┬───────────────────────────────┬─────────────────┐
│ Title │ Average Time (ms) │ CPU (%) │ RAM (MB) │ Average Infelicity Time (ms) │ Difference (%) │
├───────────────┼───────────────────┼──────────┼───────────┼───────────────────────────────┼─────────────────┤
│ SampleTitle1 │ xxxxx │ xxxxx │ xxxxx │ xxxxx │ Best │
│ SampleTitle2 │ xxxxx │ xxxxx │ xxxxx │ xxxxx │ Slower by xxxxx │
│ SampleTitle3 │ xxxxx │ xxxxx │ xxxxx │ xxxxx │ Slower by xxxxx │
└───────────────┴───────────────────┴──────────┴───────────┴───────────────────────────────┴─────────────────┘
How to use. (Inside your application)