Nodejs Benchmark 模块的使用
作者:互联网
nodejs 性能测试 benchmark
test.js
const benchmark = require('benchmark'); const suite = new benchmark.Suite; // 添加测试 suite.add('RegExp', function () { /o/.test('Hello World'); }).add('indexOf', function () { 'Hello World'.indexOf('o'); }).on('cycle', function (e) { console.log(String(e.target)) }).on('complete', function () { console.log('The fasted method is ' + this.filter('fastest').map('name')); }).run({'async': true})
output
RegExp x 26,365,573 ops/sec ±3.08% (70 runs sampled) indexOf x 786,281,744 ops/sec ±2.26% (78 runs sampled) The fasted method is indexOf
标签:function,sampled,Nodejs,indexOf,benchmark,Benchmark,sec,模块,World 来源: https://blog.51cto.com/u_15166492/2707366