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

benchart

v2.0.0

Published

Plots a performance chart for Benchmark.js results saved by astrobench-cli.

Downloads

2

Readme

benchart

Latest version Dependency status

NPM Downloads

Plots a performance chart for Benchmark.js results saved by astrobench-cli.

timeline example comparison example

Pre-requisites

Chart generation requires gnuplot installed. It is freely available on any platform.

On Linux, install from the distribution package. For example, on Ubuntu:

sudo apt install gnuplot

Using Homebrew on OSX:

brew install gnuplot

Using Chocolatey on Windows:

choco install gnuplot

Getting Started

Make sure that you have Node.js >= 10 installed. Install benchart globally:

npm i -g benchart

Plot a performance chart for all results in a directory:

$ benchart results

Testing Scenario

Testing page:

<link rel="stylesheet"
      href="https://unpkg.com/@prantlf/[email protected]/dist/astrobench.min.css">
<script src="https://unpkg.com/@prantlf/[email protected]/dist/astrobench.min.js"></script>

<div id="astrobench"></div>

<script>
  suite('A suite', suite => {
    const text = 'Hello world'
    bench('Validate greeting by regular expression', () => text.match(/^H/))
    bench('Validate greeting by comparison', () => text[0] === 'H')
  })
</script>

Tool installation:

npm i -g astrobench-cli benchart

Chart generation:

$ astrobench -j output/results.json example/index.html
$ benchart output

Command-Line Usage

The benchart script plots a chart for statistics produced by Benchmark.js and written out to JSON files by astrobench-cli.

$ benchart --help

Usage: benchart [options] <directory>|<file> ...

Options:
  -V, --version               output the version number
  -d, --out-directory <path>  path to the output directory
  -n, --out-name <name>       file name of the written chart (default: "chart")
  -p, --type <type>           type of the chart (default: "timeline")
  -t, --title <title>         chart title (default: "Benchmark Results")
  -w, --width <number>        width of the charter in pixels
  -g, --height <number>       height of the charter in pixels
  -i, --y-min <number>        minimum value on the y axis
  -a, --y-max <number>        maximum value on the y axis
  -y, --y-property <name>     property shown on the y axis (default: "hz")
  -r, --error-bars            show standard error of the mean
  -b, --x-label <label>       label of the x axis
  -e, --y-label <label>       label of the y axis
  -c, --cluster-by <input>    cluster histogram bars
  -l, --legend-place <place>  legend placement (default: "outside")
  -v, --verbose               print progress of the plotting
  -h, --help                  output usage information

 Reads all "*.json" files from the specified directory, unless a list of
 files is specified. The chart will be written to the input directory,
 unless an output directory is specified. Chart types are "timeline" or
 "comparison". Histograms can be clustered by "benchmark" or "suite".
 Legend places are "left", "right", "outside" and "under". Property shown
 on the y axis can be "hz" or "mean".

Examples:

 $ benchart results
 $ benchart -rv -t "Sizes" -d results -n comparison \
     -p comparison results/50.json results/100.json

Programmatic Usage

Make sure that you have Node.js >= 18 installed. Install benchart locally in your project with npm or yarn:

npm i benchart
yarn add benchart

Plot a chart for all JSON files in the results directory and store it with the name chart in the same directory:

const plot = require('benchart')
await plot({ directory: 'results' })

plot(options: object): Promise<>

The main module exports a function which generates the chart to the output directory and returns a Promise resolved when the chart has been written.

Recognised options:

  • directory: string - directory to look for the input JSON files
  • out-directory: string - path to the output directory
  • out-name: string - file name of the written chart (default: "chart")
  • type: string - type of the chart (default: "timeline", otherwise: "comparison")
  • title: string - chart title (default: "Benchmark Results")
  • width: number - width of the charter in pixels
  • height: number - height of the charter in pixels
  • y-min: number - minimum value on the y axis
  • y-max: number - maximum value on the y axis
  • y-property: string - property shown on the y axis (default: "hz", otherwise: "mean")
  • error-bars: boolean - show standard error of the mean (default: false)
  • x-label: string - label of the x axis
  • y-label: string - label of the y axis
  • cluster-by: string - cluster histogram bars by "benchmark" or "suite"
  • legend-place: string - legend placement (default: "outside", otherwise: "left", "right", and "under")
  • verbose: boolean - print progress of the plotting
  • verbose: boolean - print progress of the chart generation (default: false)

Data

An example of a JSON file with test results. Benchmark properties aborted, error, hz, stats and times are described in the Benchmark.js documentation:

[
  {
    "name": "A suite",
    "benchmarks": [
      {
        "name": "String#match",
        "aborted": false,
        "hz": 21672040.42791444,
        "stats": {
          "rme": 1.394724557215958,
          "mean": 4.2691777736331135e-8
        }
      },
      {
        "name": "RegExp#test",
        ...
      },
      {
        "name": "Benchmark with error",
        "error": {
          "message": "text is not defined",
          "name": "ReferenceError",
          "stack": "@test/example/bench.js:19:6
            Benchmark.uid1580598679888createFunction@test/example/index.html:3:124"
        },
        "aborted": true
      }
    ]
  }
]

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using npm.

License

Copyright (c) 2020-2024 Ferdinand Prantl

Licensed under the MIT license.