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

toofast

v3.0.3

Published

The Node.js performance testing tool with unit-test-like API.

Readme

The Node.js performance testing tool with unit-test-like API.

  • Runs each test in a separate process;
  • Measures execution time using performance;
  • Runs tested functions in multiple batches to reduce garbage collection interference;
  • Warms up tested functions;
  • Measures memory consumption using process.memoryUsage.
npm install toofast --save-dev

🔰 Usage

🚀 Authoring tests

⚙️ Configuration

Usage

Let's write a performance test for a function that computes a factorial.

Create a file factorial.perf.js:

import { describe, test, measure } from 'toofast';

function factorial(x) {
  return x === 0 ? 1 : x * factorial(x - 1);
}

describe('factorial', () => {

  test('of 33', () => {
    measure(() => {
      factorial(33);
    });
  });

  test('of 42', () => {
    measure(() => {
      factorial(42);
    });
  });
});

Call toofast in the same directory with this file:

npx toofast

Authoring tests

TooFast package exports several callbacks that you can use in test file.

test

The minimum setup that you need in a test file is the test callback which encloses a group of measurements. For example, let's say there's a function factorial which performance must be measured. Your whole test could be:

import { test, measure } from 'toofast';

test('factorial of 33', () => {
  measure(() => {
    factorial(33);
  });
});

The measure callback starts the performance measurement. It can be invoked multiple times inside a test block to collect a data population from which an average results are derived.

test('factorial of 33 and 42', measure => {

  measure(() => {
    factorial(33);
  });

  measure(() => {
    factorial(42);
  });
});

The measure callback returns a promise that is resolved as soon as performance measurement is completed.

describe

Creates a block that groups together several related tests.

import { describe, test, measure } from 'toofast';

describe('factorial', () => {

  test('of 42', measure => {
    measure(() => {
      factorial(42);
    });
  });
});

describe blocks can be nested:

describe('Math', () => {

  describe('factorial', () => {
    // Tests go here
  });
});

Lifecycle hooks

Hooks are invoked at different phases of the performance test suite lifecycle: beforeEach, afterEach, afterWarmup, beforeBatch, afterBatch, beforeIteration, and afterIteration.

The chart below demonstrates when they are called.

flowchart TD

describe --> testLifecycle

subgraph testLifecycle [Test lifecycle]
    direction LR

    subgraph warmup [Warmup]
        direction TB
        warmup_beforeWarmup(beforeWarmup) -->
        warmup_beforeBatch(beforeBatch) -->
        warmup_beforeIteration(beforeIteration) -->
        warmup_callback[callback] -->
        warmup_afterIteration(afterIteration) -->
        warmup_afterBatch(afterBatch) -->
        warmup_afterWarmup(afterWarmup)
    end

    subgraph batch [Measure]
        direction TB
        measure_beforeBatch(beforeBatch) -->
        measure_beforeIteration(beforeIteration) -->
        measure_callback[callback] -->
        measure_afterIteration(afterIteration) -->
        measure_afterBatch(afterBatch) -->
        measure_beforeBatch
    end

    beforeEach(beforeEach) -->
    test -->
    warmup -->
    batch -->
    afterEach(afterEach)
end

Hooks can be registered at root level, or inside a describe or test block. Registered hooks affect all measure calls that are nested in a block.

Hooks are always registered before any measurements are started, so the code below would first register beforeEach and beforeIteration hooks and only after that would run measure.

import { beforeEach, beforeIteration, describe, test, measure } from 'toofast';

describe('factorial', () => {

  beforeEach(() => {
    // Runs before each test
  });

  test('of 42', () => {
    measure(() => {
      factorial(42);
    });

    beforeIteration(() => {
      // Runs before each measure() iteration
    });
  });
});

TypeScript support

TooFast can automatically strip TypeScript types without any additional configuration if *.{ts,mts} files are included:

toofast --include '**/*.perf.ts'

This feature requires Node.js 22.6+.

Configuration

By default, TooFast searches for .toofastrc, toofast.json, or toofast.config.js in the current working directory.

{
  "testOptions": {
    "measureTimeout": 5000
  },
  "include": [
    "**/*.perf.js"
  ]
}

The default test options used for all tests.

The array of glob patterns of included test files. File paths are resolved relative to the config file. Defaults to **/*.perf.{js,mjs,ts,mts}.

The array of glob patters of files that are evaluated in the test environment before any test suites are run. File paths are resolved relative to the config file.

Test options

The maximum measure duration in milliseconds. Doesn't include the duration of warmup iterations. Defaults to 10_000.

The maximum relative margin of error that must be reached for each measurement [0, 1]. Defaults to 0.05.

The maximum number of warmup iterations that are run before each measurement. Defaults to 1. Set to 0 to disable warmup.

The maximum number of iterations in a batch. Unlimited by default.

The maximum duration of batched measurements in milliseconds. Defaults to 1_000.

The delay between batched measurements in milliseconds. VM is expected to run garbage collector during this delay. Defaults to 200.

Command line arguments

The path to a configuration file.

toofast --config toofast.cfg

The array of glob patterns of included test files.

File paths are resolved relative to the current working directory. Provide this option multiple times to include multiple patterns. include option is specified in a config file is overridden by --include arguments.

toofast --include '**/*.perf.js' --include './perf/**/*.mjs'

The array of glob patters of files that are evaluated in the test environment before any test suites are run.

File paths are resolved relative to the current working directory. Provide this option multiple times to include multiple patterns. setup option is specified in a config file is overridden by --setup arguments.

toofast --setup setup.perf.js

The maximum measure duration in milliseconds. Overrides measureTimeout test option.

The maximum relative margin of error that must be reached for each measurement [0, 1]. Overrides targetRme test option.

toofast --targetRme 0.01

The maximum number of warmup iterations that are run before each measurement. Overrides warmupIterationCount test option.

The maximum number of iterations in a batch. Overrides batchIterationCount test option.

The maximum duration of batched measurements in milliseconds. Overrides batchTimeout test option.

The delay between batched measurements in milliseconds. Overrides batchIntermissionTimeout test option.

The array of glob patterns to filter tests that must be executed across all included files.

toofast 'factorial*'

Inline options

Provide option overrides to a particular describe, test and measure blocks. Options provided to a block override both config options and command line arguments. Block-level options are propagate to all underlying blocks as well.

import { describe, test, measure } from 'toofast';

describe('factorial', () => {

  test('of 33', { warmupIterationCount: 1000 }, () => {
    measure(() => {
      factorial(33);
    });
  });
});