npm run <cmd>运行缓慢

Ale*_*der 5 performance node.js npm

我曾经通过Makefile运行各种命令但是对于nodejs项目,package.json是一个更合适的地方.

通过npm运行命令可以很好地工作,但与命令时间执行相比非常慢.

$ time ./node_modules/.bin/jshint . && ./node_modules/.bin/jscs .

real    0m0.759s
user    0m0.524s
sys 0m0.085s
No code style errors found.

$ time npm run lint

> @ lint /path/to/project
> jshint . && jscs .

No code style errors found.

real    0m2.246s
user    0m1.637s
sys 0m0.277s
Run Code Online (Sandbox Code Playgroud)

有可能加快速度吗?

UPD.我的package.json:

{
  "devDependencies": {
    "jscs": "^1.12.0",
    "jshint": "^2.6.3"
  },
  "scripts": {
    "lint": "jshint . && jscs ."
  }
}
Run Code Online (Sandbox Code Playgroud)

UPD2.我以错误的方式测量时间.甘特在他的评论中指出了这一点.现在两次看起来相似(100毫秒的差异).

$ time sh -c './node_modules/.bin/jshint . && ./node_modules/.bin/jscs .'
No code style errors found.

real    0m1.704s
user    0m1.245s
sys 0m0.177s
$ time npm run lint

> @ lint /path/to/project
> jshint . && jscs .

No code style errors found.

real    0m1.822s
user    0m1.621s
sys 0m0.198s
Run Code Online (Sandbox Code Playgroud)

Aur*_*lia 7

这不是npm的错,事实上它甚至可以更准确地测量时间.

让我们来看看你做了什么.

time npm run lint将调用时间,然后按顺序调用您的任务.time停止时将停止占用所需的时间npm,这将在您的任务完成后运行.这里只有轻微的开销,脚本按预期工作.

time ./node_modules/.bin/jshint . && ./node_modules/.bin/jscs .但是会调用time,这将调用jshint.一旦jshint退出,时间也将退出并且jscs将在没有时间运行.这也是为什么在您的示例中输出顺序混淆的原因.

要获得没有npm的准确时间测量,请尝试 time sh -c './node_modules/.bin/jshint . && ./node_modules/.bin/jscs .'