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

measure-loop

v0.3.8

Published

An accurate, runtime-agnostic benchmarking loop.

Downloads

2,576

Readme

measure-loop

An accurate, runtime-agnostic measure loop for benchmarking purposes.

Usage

import { bench, env } from 'measure-loop/runner';
import reporter from 'measure-loop/reporter';

await bench()
  .it('performance.now()', [], () => performance.now())
  .it('Date.now()', [], () => Date.now())
  .run({ env, reporter });

To run:

bun run bench.ts

# Expose manual GC for V8-based runtime.
node --expose-gc bench.ts
deno run --v8-flags=--expose-gc bench.ts
...

To collect GC time:

import { bench, env } from 'measure-loop/runner';
import reporter from 'measure-loop/reporter';

await bench()
  .it('performance.now()', [], () => performance.now(), { measureGC: true })
  .it('Date.now()', [], () => Date.now(), { measureGC: true })
  .run({ env, reporter });

// to apply to all child benchmarks
await bench({ measureGC: true })
  .it('performance.now()', [], () => performance.now())
  .it('Date.now()', [], () => Date.now())
  .run({ env, reporter });

To add computed parameters:

// Doesn't get measured
const params = [
  (i) => generateString(i + 1),
  () => 'abc'
] as const;

const acTrie = buildTrie('abc');

bench()
  .it(
    'knuth-morris-pratt',
    params,
    (str, substr) => kmp(str, substr)
  )
  .it(
    'boyer-moore',
    params,
    (str, substr) => bm(str, substr)
  );
  .it(
    'boyer-moore-horspool',
    params,
    (str, substr) => bmh(str, substr)
  )
  .it(
    'aho-corasick',
    [
      (i) => generateString(i + 1),
      () => acTrie
    ],
    (str, trie) => ac(str, trie)
  );

Options

Benchmark options can be passed in two ways:

// Apply options to all child benchmarks
bench({ gcOnce: true })
  .it('performance.now()', [], () => performance.now())
  .it('Date.now()', [], () => Date.now());

// Apply options to a specific benchmark
bench()
  .it('performance.now()', [], () => performance.now(), {
    gcOnce: true
  })
  .it('Date.now()', [], () => Date.now());

// Both
bench({ iters: 120, gcOnce: false })
  .it('performance.now()', [], () => performance.now(), {
    // Override gcOnce option but still keep iters = 120
    gcOnce: true
  })
  .it('Date.now()', [], () => Date.now());

Measure options:

  • warmupIters: Warmup iterations count, defaults to 16.
  • iters: Benchmark iterations count, defaults to 128.
  • debug: Include debug info in result, defaults to false.

Compile options:

  • batch: Number of calls in an iteration, defaults to 4096.
  • inlineCalls: Number of calls to inline in an iteration, defaults to 4.
  • measureGC: Whether to collect GC timings, enable this may affect runs timing accuracy, defaults to false.
  • gcOnce: Whether to only gc() on start instead of every iteration, enable this when your benchmark code have few allocations to increase runs timing accuracy.

Categories

Benchmarks can be separated into categories:

import { bench, category, env } from 'measure-loop/runner';
import reporter from 'measure-loop/reporter';

const runtimeValidators = bench()
  .it(...)
  .it(...);

const jittedValidators = bench()
  .it(...)
  .it(...);

await category()
  .it('runtime', runtimeValidators)
  .it('jit', jittedValidators)
  .run({ env, reporter });

Default options can be passed down similar to bench:

category({ gcOnce: true })
  .it(...)
  .it(...);

Categories can be nested:

const runtimeValidators = category()
  .it(...)
  .it(...);

const jittedValidators = category()
  .it(...)
  .it(...);

// Default options if specified will be passed down to child categories
category()
  .it('runtime', runtimeValidators)
  .it('jit', jittedValidators);