JS、TS仓的性能评估工具
通常可以通过一下方式进行性能分析:
- 直接使用node进行性能分析
- 使用jest进行性能分析
- console.time/console.timeEnd
node
node已经内置了profiling工具, 这里要补充一个点就是
- 使用
--prof选项运行node执行程序, 会生成isolate-0xXXX-v8.log的文件 - 安装
v8-log-converter:
npm install -g v8-log-converter- 转换文件, 转换后的文件可以通过浏览器的devtool进行分析
v8-log-converter isolate-0xXXX-v8.log > v8.json- 也可以通过
tick-processor进行查看
npm install -g tick-processor
tick-processor isolate-0xnnnnnnnnnnnn-v8.log > processed.txt- 使用node自带的解析工具也可以
node --prof-process isolate-0xnnnnnnnnnnnn-v8.log > processed.txt
# 下面这条命令也能work
node --prof-process isolate-* > processed.txt如果发生 stdout is not a tty的报错, 使用 node.exe进行即可. 看到是在 git bash以及 msys bash都会出问题, powershell没有.
jest
在jest内置 v8-profiler-next结合测试用例进行分析
v8-profiler-next
在安装 v8-profiler-next的过程中会出现安装问题, 需要补充
npm config set strict-ssl false
yarn config set strict-ssl false在安装完后能够看到 node_modules/v8-profiler-next/build目录, 表明 v8-profiler-next安装正确.
