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 🙏

© 2024 – Pkg Stats / Ryan Hefner

nano-benchmark

v1.0.4

Published

Small utilities to benchmark code with Node.

Downloads

195

Readme

nano-benchmark NPM version

nano-benchmark provides command-line utilities for benchmarking code and related statistical modules.

Two utilities are available:

  • nano-watch — provides statistics in a streaming mode continuously running your code, watching memory usage and updating the output.
  • nano-bench — runs benchmark tests on your code, calculating statistics and statistical significance, and presenting them in a tabular format.

The utilities are mostly used to measure performance of your code and compare it with other variants. It is geared toward benchmarking and performance tuning of small fast snippets of code, e.g., used in tight loops.

Visual samples

nano-watch

nano-watch

nano-bench

nano-bench

Installation

npm install --save nano-benchmark

Deno and Bun support

Both deno and bun are supported.

If you want to run the benchmark in Deno, Bun, etc. you can specify self as the file argument or the --self option. In this case the utility will print out its file name to stdout and exit. It allows running the utility with alternative JavaScript interpreters.

Examples with bash:

npx nano-bench benchmark.js
bun `npx nano-bench --self` benchmark.js
deno run --allow-read --allow-hrtime `npx nano-bench --self` benchmark.js
deno run -A `npx nano-bench --self` benchmark.js
node `npx nano-bench --self` benchmark.js

Don't forget to specify the appropriate permissions for Deno to run the benchmark scripts: --allow-read (required) and --allow-hrtime (optional but recommended). Or consider using -A or --allow-all to allow all permissions (used it only in safe environments!).

Documentation

Both utilities are available by name if you installed nano-benchmark globally (npm install -g nano-benchmark). If it is installed as a dependency, you can use utilities by name in the scripts section of your package.json file or from the command line by prefixing them with npx, e.g., npx nano-watch.

Utilities are self-documented — run them with --help flag to learn about arguments.

Both utilities import a module to benchmark using its (default) export. nano-bench assumes that it is an object with functional properties, which should be benchmarked and compared. nano-watch can use the same file format as nano-bench or it can use a single function.

Example of a module for nano-bench called bench-strings-concat.js:

export default {
  strings: n => {
    const a = 'a',
      b = 'b';
    for (let i = 0; i < n; ++i) {
      const x = a + '-' + b;
    }
  },
  backticks: n => {
    const a = 'a',
      b = 'b';
    for (let i = 0; i < n; ++i) {
      const x = `${a}-${b}`;
    }
  },
  join: n => {
    const a = 'a',
      b = 'b';
    for (let i = 0; i < n; ++i) {
      const x = [a, b].join('-');
    }
  }
};

The way to use it:

npx nano-bench bench-strings-concat.js
npx nano-watch bench-strings-concat.js backticks

See wiki for more details.

License

BSD 3-Clause License

Release history

  • 1.0.4: Updated dependencies + added more tests.
  • 1.0.3: Updated dependencies.
  • 1.0.2: Added the --self option.
  • 1.0.1: Added "self" argument to utilities so it can be used with Deno, Bun, etc.
  • 1.0.0: Initial release.