Catalog npm
PACKAGE EXPLORERView in registry

@0j3/bench-js

npm

A generic Benchmarking tool

bench.jsbenchmarkperformancetesting
Versions collected5
Direct dependencies2From release 1.0.1
Last observed20 Oct, 22:11 UTC

README

Current package documentation

bench.js Known Vulnerabilities

a benchmarking tool in nodejs

Installing

yarn add @0j3/bench-js

Usage

To use bench.js, start by initializing it:

const benchjs = new (require("bench-js"))(true); // The first argument in the constructor of bench.js (the "true") specifies, if benchjs.finish (see below) should output anything

Then, start by creating a "Task" where your program does something you want to benchmark (you can have infinite tasks, and you should make anything that takes lots of time have a task), by using

const task = benchjs.createTask("Sample Task Name");

at the beginning of you code.

To start the task (specify when it's execution starts), use

task.begin();

IMPORTANT: DO NOT CALL Task.start AS THAT IS AN INTEGER SPECIFYING WHEN IT STARTED!


To tell Bench.JS when a task is finished, use

task.finish();

To tell Bench.JS that a task has errored, use

task.error(new Error("Error Message Here"));

At the end of your code, you must add

benchjs.finish(0);

The 0 is optional, and specifies the exit code.

When running finish, bench.js will exit your program, once its done outputting the benchmark data, so it is important that you have nothing else running after this.

Bench.JS Sample Output

Taken from the Tests File

===== BENCHMARK FINISHED =====
Task Node (#0) took 0.10054s
Task App (#1) took 0.02517s
Task Sample Task 1 (#2) took 0.00005s
Task Sample Task 2 (#3) took 0.00005s
Task Sample Task 3 (#4) took 0.00004s
Task Sample Task 4 (#5) DNF | Error (See C:\PATH/TO/BENCHJS/errors/21.9.2020-18.33.5/Sample-Task-4-id-5.err.yml)
Task Sample Task 5 (#6) DNF
Task Finish writing to error files (#7) took 0.0146s
==============================

Extending Bench.JS

If you want to extend bench.js, use

const BenchOriginal = require("benchjs");
class Bench extends BenchOriginal {
  constructor(outputResults = true) {
    super.constructor(outputResults); // call original constructor
  }
}

and add whatever you want from there.


If you want to extend the task class aswell, use

const BenchOriginal = require("benchjs");
class Task extends BenchOriginal.Task {
  constructor(taskName, id, parent) {
    super.constructor(taskName, id, parent); // call original constructor
  }
}

class Bench extends BenchOriginal {
  constructor(outputResults = true) {
    super.constructor(outputResults); // call original constructor
    super.TaskClass = Task;
  }
}

and add whatever you want from there.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 5

Collected releases
VersionPublishedDirect dependenciesOpen version
1.0.1Registry latest21 Oct 20202
1.0.1-121 Oct 20202
1.0.1-021 Oct 20202
1.0.021 Oct 20202
0.0.021 Oct 20202

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:11 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:12029d29dedeb1b4f79e591eb6fd8d1d1a5693d39b7a18c010f96252729961a4