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

silver-bench

v0.0.3

Published

A fast and configurable benchmarking tool for JS/TS

Downloads

42

Readme

silver-bench

A fast and configurable benchmarking tool for JS/TS.

Usage

In your project, run:

npm i silver-bench

Then create a file named vec2.bench.ts that looks like this:

import {perf} from "silver-bench"

perf("add", () => {
  // setup
  const a = {x: 0, y: 0}
  const b = {x: 1, y: 2}
  // run
  return () => {
    a.x += b.x
    a.y += b.y
  }
})

Run npx silver-bench. The output should look similar to this:

running benchmarks in /Users/eric/projects/silver-bench-test

/vec2.bench.ts
add  3,759,398 ops/s

Finally, run npx silver-bench again. You'll now see the delta between the previous run and the latest run to the right of the perf results:

/vec2.bench.ts
add  3,623,188 ops/s  -0.45%

Config

The benchmark tool is configurable through use of enivronment variables, command line arguments, and perf settings.

Environment variables

# An object whose properties should be added to `globalThis` in your benchmark
# files.
BENCH_GLOBALS="{}"
# File extension used to locate benchmarks in the directory where `silver-bench`
# is run.
BENCH_MODULE_EXTENSION="bench.ts"
# File extension used for benchmark results. You may want to add this pattern
# to your gitignore file.
BENCH_RESULTS_EXTENSION="bench-results.csv"
# The unit of time used to report perf results.
PERF_UNIT="s"
# Number of perf results to discard on either end of the results spectrum. This
# option helps eliminate outliers caused by code optimization.
PERF_SAMPLES_TO_DISCARD_PER_EXTREME=100
# Number of times to run each perf.
PERF_ITERATIONS=2000
# The deviation at which perf results are reported in green and written to the
# perf results file.
PERF_SUCCESS_THRESHOLD=0.2
# The deviation at which perf results are reported in yellow and written to the
# perf results file.
PERF_WARNING_THRESHOLD=-0.2
# The deviation at which perf results are reported in red. Failures are not
# written to the perf results file.
PERF_FAILURE_THRESHOLD=-0.3
# If true, failures are written to the perf results file. This is useful if you
# make a change where you expect a degradation in performance.
WRITE_FAILURES=false

Perf settings

You can define a perf with the desired number of iterations using perf().iterations(n):

perf("add", () => {
  const x = 1
  const y = 1
  return () => x + y
}).iterations(15_000)