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

what-code-is-faster

v1.0.0

Published

Speedy and correct JS perf comparisons

Downloads

18

Readme

What Code Is Faster?

A browser-based tool for speedy and correct JS performance comparisons!

  • Minimalistic UI
  • Code editor with IntelliSense
  • All state is saved to URL - copy it and share with friends in no time!
  • Automatically determines the number of iterations needed for a proper measurement — no hard-coding!
  • Prevents dead code elimination and compile-time eval. optimizations from ruining your test!
  • Verifies correctness (functions must compute the same value, be deterministic, depend on their inputs)
  • Warms up functions before measuring (to give time for JIT to compile & optimize them)

How Does It Work?

Benchmarked functions are written as reducers, i.e. taking a previous value and returning some other value. The runtime executes your functions in a tight loop against some random initial value, saving the final value to a global variable (thus producing a side effect), so that no smart compiler could optimize out our computation!

So you must also provide a random initial value (not something like that) and ensure that your reducers follow some simple rules. Those rules are programmatically enforced — so you won't shoot yourself in the foot. Check the examples to get a sense of how to write a benchmark.

The rules:

  1. The result of a function must depend on its input — and only on its input! You cannot return the same value again and again, or return some random values — there should be some genuine non-throwable computation on a passed input.

  2. Given the same input, the output of the functions must be all the same. The comparison should be fair — we want to compare different implementations of exactly the same thing!

Examples

  • for..of or counter-based for?

  • for..in or Object.entries?

  • Array push vs. assign to last index

  • BigInt (64-bit) vs. number (increment)

  • Math.hypot or Math.sqrt?

  • Do local function declarations affect performance?

  • Do closures affect performance (vs. free functions)?

  • For..of loop over Set vs. Array

  • For..of loop over Object.values vs. Map.forEach (large integer keys)

  • Map vs. Object (lookup)

  • Map vs. Object (getting keys)

  • Null or undefined? (equality check)

  • Arguments passing: spread vs. call() vs. apply()

  • JSON.parse() vs. eval()

  • Array vs TypedArray Dot Product

  • instanceof or constructor check?

  • Copying: arr.slice() vs. [...arr]

  • new Array(length).fill(N) vs. Array.from({length}).fill(N)

  • ..Add your own? Pull Requests are welcome!

Extended Configuration

In case you test functions operate on differently typed inputs, you might need to provide distinct initial values and provide a customized comparison function, otherwise it won't pass the soundness check. Here is an example:

benchmark(
  'bigint vs number (addition)',
  {
    initialValues() {
      const seed = (1000000 + Math.random() * 1000) | 0
      return {
        bigint: BigInt(seed),
        number: seed
      }
    },
    equal(a, b) {
      return BigInt(a) === BigInt(b)
    }
  },
  {
    bigint(prev) {
      return prev + 1n
    },
    number(prev) {
      return prev + 1
    }
  }
)

npm package

npm install what-code-is-faster
import { benchmark } from 'what-code-is-faster'

Works same as benchmark in UI, but prints results with console (node/browsers).

There also lower level checkSoundness and measureExecutionTime exports if you need to build a custom progress/results reporter.