npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@0j3/bench-js

v1.0.1

Published

A generic Benchmarking tool

Downloads

17

Readme

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.