Skip to content

Instantly share code, notes, and snippets.

@martinheidegger
Last active December 6, 2016 05:03
Show Gist options
  • Save martinheidegger/32d00e90e0163a22a4ffc78df796001e to your computer and use it in GitHub Desktop.
Save martinheidegger/32d00e90e0163a22a4ffc78df796001e to your computer and use it in GitHub Desktop.
Timing NPM config performance in various node js versions

Timing npm config get prefix in order to test the performance problems of nvm. To run the tests you need to install 4, 5, 6, 7.0, 7.1 and 7.2 version of node with nvm and you should make sure that the correct version of npm is installed for each node version.

(Related to nvm-sh/nvm#1277)

(Note that the output is of the tests run on ubuntu 14.04)

#!/bin/bash
source "$NVM_DIR/nvm.sh"
times() {
total=0.0
for n in {1..10}; do
local duration=$(/usr/bin/time -f %e $@ 2>&1 1>/dev/null)
total=$(bc <<< "$duration + $total")
done
printf $(bc <<< "$total * 0.1")
}
echo "\"node -v\", \"npm -v\", \"npm config get prefix ... 10\", \"node -p 1+1 ... 10\", \"./npm_config_hack.sh \$npm_home ... 10\""
for node in 4 5 6 "7.0" "7.1" "7.2"; do
nvm i $node >/dev/null 2>&1
npm_home=$(npm config get prefix)/lib/node_modules/npm
echo "\"$(node -v)\", \"$(npm -v)\", $(times npm config get prefix), $(times node -p 1+1), $(times ./npm_config_hack.sh $npm_home)"
done
#!/bin/bash
prefix=$1
node -e "require('$prefix/lib/config/core.js').load('$prefix/npmrc', {}, function (er, config) { console.log(config.get('prefix')) })"
node -v npm -v npm config get prefix ... 10 node -p 1+1 ... 10 ./npm_config_hack.sh $npm_home ... 10
v4.6.2 2.15.11 .50 .05 .21
v5.12.0 3.10.10 .55 .05 .18
v6.9.1 3.10.10 .55 .06 .20
v7.0.0 3.10.10 .47 .06 .20
v7.1.0 3.10.10 .51 .06 .19
v7.2.0 3.10.10 .57 .06 .25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment