v8-profiler-node8
安装好v8-profiler-node8
npm i v8-profiler-node8
CPU性能分析
在要测试的代码块前后进行profiling,然后将profiler保存至本地文件
const profiler = require('v8-profiler-node8')
const start = () => {
profiler.startProfiling('fuck')
const inputStr = 'A B A B A B A B B B A B A B A A C D A C D A D C A B A A A B A B'.replace(/\s/g, '')
for (let i=0; i<1000000; i++)
lzwCompress(inputStr)
profiler.stopProfiling('fuck').export()
.pipe(fs.createWriteStream('fuck.json'))
}
https://www.speedscope.app/
使用speedscope在线工具分析刚生成的json文件