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

@folkol/criterion

v0.0.27

Published

Micro-benchmarking tool inspired by Criterion.rs

Readme

Criterion.js

Criterion.js is a micro-benchmarking tool (heavily!) inspired by Criterion.rs which is inspired by Criterion.hs which was inspired by an unnamed benchmarking framework introduced in a series of blog posts by Brent Boyer. (The blog posts were published on IBM's developerWorks which has since been decommissioned, but copies of the posts can still be found in the Internet Archive.)

What does it do?

For each of your benchmarks, it does something like this:

  1. runs your benched function in a loop for some time in order to get the system up-to-speed (JIT compilation, various system caches, CPU P-states, etc.)
  2. runs your code a few times more in order to measure its performance (awaiting the result of each invocation if the return value is 'thenable')
  3. calculates some statistics for these measurements
  4. (generates HTML report)

Caveats

Micro-benchmarking is what it is, if your production code isn't executed in a tight loop isolated from the outside world the results from these test might not apply to the real world.

Do not run on untrusted input

There is some rudimentary input validation in place to mitigate programming errors and similar mistakes, but this package is not safe for use on untrusted input. (For example: The plot generator will include the group and function names into Gnuplot scripts before executing them.)

Gnuplot

Gnuplot is needed for report generation. (gnuplot 5.4 patchlevel 8 on macOS seems to work.)

Unstable API

The code changes a lot, if you run into 'weird problems' -- try removing any test outputs created by an older version of Criterion.

How do I get it?

$ npm install (--save-dev) @folkol/criterion

How do I use it?

  1. Create a Criterion instance
  2. Create a benchmark group
  3. Bench a number of functions
  4. [optionally] Generate the report
import {Criterion} from '@folkol/criterion';
import {f, g} from "./my-module";

let criterion = new Criterion({
//    measurementTime: 0.1,
//    nResamples: 10,
//    warmUpTime: 0.1,
});

let group = criterion.group("f vs g");

group.bench("f", f);
group.bench("g", g);

How do I run it?

$ node path/to/my/benchmark.js
$ npx criterion-report ./criterion/

CRITERION_ENV

If you want to compare your functions in different runtime environments, you can set the CRITERION_ENV environment variable -- and you will get synthetic tests with the env name appended:

$ node path/to/my/benchmark.js
$ CRITERION_ENV=bun bun path/to/my/benchmark.js
$ npx criterion-report ./criterion/

CRITERION_ENV example

How do I interpret the regression plots?

The Regression plot can be used to judge the quality of the sample. Each measurement will use increasingly higher iteration counts -- and the expectation is that the time for each sample goes up as the number of iterations increases. If this is not the case, the samples might not be independent -- or something happened that changed time per iteration (garbage collection pauses, optimizing compilation, something hogged the CPU, the laptop switched to battery power?). In any case, if the dots on the regression plot aren't close to the line, be careful when interpreting the results.

Here is an example where 'something' happened during the test. My guess is that the routine got optimized half-way through, and that we should re-run the test with a longer warmup time.

Unhealthy

Unhealthy

Healthy

Healthy

TODO

  • More plots!
  • Port more bench functions from Criterion.rs (Parameterized tests, tests of functions that consume their input, etc.)
  • Separate report generation into its own package?