Benchmarking Install Time: A Method for Package Authors
Users notice when adding your package makes npm install or pip install noticeably slower, especially in CI where they pay for every second. Measuring install time sounds trivial, but a single stopwatch run tells you almost nothing. This page sets out a method you can repeat on every release. It deliberately contains no results: yours will depend on your machine, network and dependency tree.
Decide what you are measuring
There are three different install scenarios and they behave very differently:
- Cold install: empty package cache, no
node_modulesor virtual environment. This is what a fresh CI runner without caching sees, and it is dominated by network transfer and the size of the dependency tree. - Warm cache install: the package manager cache is populated but the project directory is clean. This is a typical cached CI job and mostly measures extraction and linking.
- Incremental install: the project already has its dependencies and you add your package. This is closest to a developer's first impression.
Pick one scenario per measurement and say which one you used. Mixing them is the most common reason benchmark numbers are not comparable.
Set up a controlled test project
Create a throwaway project that depends only on your package, with a committed lockfile so every run resolves the same versions. For npm:
mkdir bench-install && cd bench-install
npm init -y
npm install your-package@1.4.0 --package-lock-only
# cold run: clear cache and node_modules, then use npm ci
npm cache clean --force && rm -rf node_modules && npm ci
For Python, create a fresh virtual environment per run and install from a pinned requirements file, ideally with hashes. If your package ships compiled extensions, note whether a wheel exists for the test platform: building from source and installing a wheel are different benchmarks entirely.
Repeat and summarise
Network jitter makes single runs useless. A command-line benchmarking tool such as hyperfine can run the same command many times, with a preparation step that resets the state before each run:
hyperfine --warmup 1 --runs 10 \
--prepare 'rm -rf node_modules' \
'npm ci --prefer-offline'
Report the median and the spread, not the best run. Record the package manager version, runtime version, operating system and whether the cache was warm. Without those, a later comparison means nothing.
Find what is slow
Once you have a stable baseline, change one thing at a time and re-measure:
- Remove or replace one heavy transitive dependency.
- Drop an install script (
postinstall), which also improves security posture for your users. - Ship prebuilt binaries or wheels instead of compiling on install.
- Trim the published files with the
filesfield or aMANIFEST.inso the tarball is smaller.
Comparing against another package
If you compare your package with an alternative, run both in the same session, on the same machine, with the same scenario, and publish the script you used. Present the comparison as "in our setup" rather than as a universal fact, and invite people to rerun it. That is more convincing than any single number. For the size side of the same question, see our notes on bundle size measurement.