Skip to content

Instantly share code, notes, and snippets.

@plmercereau
Created October 19, 2022 09:21
Show Gist options
  • Save plmercereau/35fe8c2ad52735a7de10214ff97423fa to your computer and use it in GitHub Desktop.
Save plmercereau/35fe8c2ad52735a7de10214ff97423fa to your computer and use it in GitHub Desktop.
Benchmark different Node package managers
#!/usr/bin/env bash
output=result.csv
> $output
benchmark () {
echo "Benchmarking $1"
pnpm run clean:all
# * `date` does not support milliseconds in macos
from=$(perl -MTime::HiRes=time -e 'printf "%.9f\n", time')
eval $2
to=$(perl -MTime::HiRes=time -e 'printf "%.9f\n", time')
result=$(echo $from $to | awk '{print $2 - $1}')
echo $result
echo "$1,$result" >> $output
}
rm -f pnpm-lock.yaml
benchmark "pnpm without lockfile" "pnpm install"
benchmark "pnpm with lockfile" "pnpm install"
rm -f yarn.lock
benchmark "Yarn without lockfile" "yes '' | yarn install"
benchmark "Yarn with lockfile" "yes '' | yarn install"
rm -f package-lock.json
benchmark "npm without lockfile" "npm install --legacy-peer-deps"
benchmark "npm with lockfile" "npm install --legacy-peer-deps"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment