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 🙏

© 2025 – Pkg Stats / Ryan Hefner

nanobench

v3.0.0

Published

Simple benchmarking tool with TAP-like output that is easy to parse

Downloads

594,797

Readme

nanobench

Simple benchmarking tool with TAP-like output that is easy to parse.

npm install nanobench

Usage

var bench = require('nanobench')

bench('sha256 200.000 times', function (b) {
  var crypto = require('crypto')
  var data = new Buffer('hello world')

  b.start()

  for (var i = 0; i < 200000; i++) {
    data = crypto.createHash('sha256').update(data).digest()
  }

  b.end()
})

bench('sha1 200.000 times', function (b) {
  var crypto = require('crypto')
  var data = new Buffer('hello world')

  b.start()

  for (var i = 0; i < 200000; i++) {
    data = crypto.createHash('sha1').update(data).digest()
  }

  b.end()
})

Running the above will produce output similar to this:

NANOBENCH version 2
> node example.js

# sha1 200.000 times
ok ~554 ms (0 s + 554449000 ns)

# sha256 200.000 times
ok ~598 ms (0 s + 597703365 ns)

all benchmarks completed
ok ~1.15 s (1 s + 152152365 ns)

API

benchmark(name, run)

Add a new benchmark. run is called with a benchmark object, b that has the following methods

  • b.start() - Start the benchmark. If not called the bench will be tracked from the beginning of the function.
  • b.end() - End the benchmark. Returns the time elapsed in milliseconds.
  • b.elapsed() - Return the time elapsed in milliseconds.
  • b.error(err) - Benchmark failed. Report error.
  • b.log(msg) - Log out a message

benchmark.skip(name, run)

Skip a benchmark.

benchmark.only(name, run)

Only run this benchmark.

CLI

If you have multiple benchmarks as different files you can use the cli benchmark runner to run them all

npm install -g nanobench
nanobench benchmarks/*.js

Comparing benchmarks

A comparison tool for comparing two benchmark outputs is included as well. This is useful if fx you ran a benchmark on two different git checkouts and want to compare which one was the fastest one

> git checkout hash-using-sha256
> node benchmark.js > output-sha256
> git checkout hash-using-blake2b
> node benchmark.js > output-blake2b

nanobench-compare output-sha256 output-blake2b

The compare tool will print out something like this

NANOBENCH version 2               |    NANOBENCH version 2
> node benchmark.js               |    > node benchmark.js
                                  |
# hashing 200.000 times          >>>   # hashing 200.000 times
# (using sha256)                 >>>   # (using blake2b)
ok ~591 ms (0 s + 590687187 ns)  >>>   ok ~95 ms (0 s + 95347216 ns)
                                  |
all benchmarks completed         >>>   all benchmarks completed
ok ~591 ms (0 s + 590687187 ns)  >>>   ok ~95 ms (0 s + 95347216 ns)
                                  |

Where >>> means that right one was faster, <<< that the left one was, and === that they were within 5% of other

Parser

An parser for the output format is included as well. You can require it from node using

var parse = require('nanobench/parse')
var output = parse(outputAsString)
console.log(output)

If you parse the above example output an object similar to this will be printed out

{ type: 'NANOBENCH',
  version: 2,
  command: 'nanobench example.js',
  benchmarks:
   [ { name: 'sha256 200.000 times',
       output: [],
       error: null,
       time: [Object] },
     { name: 'sha1 200.000 times',
       output: [],
       error: null,
       time: [Object] },
     { name: 'sha256 200.000 times',
       output: [],
       error: null,
       time: [Object] } ],
  error: null,
  time: [ 1, 802600099 ] }

License

MIT