Check your code perfomance in Node.js
npm install perf-chkjavascript
const iterations = 10000000;
console.time("function A");
for(let i=0; i // some code1
}
console.timeEnd("function A"); // 'Function A: xxx.xxx ms'
console.time("function B");
for(let i=0; i // some code2
}
console.timeEnd("function B"); // 'Function B: xxx.xxx ms'
`
but I can't remember upper code.
So I copy & paste upper code,
and edit many code(function name, code, iteration count).
It is very annoying...
so I made perf-chk!What is perf-chk?
It is execution time checker in Node.js.
Use perf-chk if you want to know which code is faster. Getting Started
perf-chk uses some ES6 features. (const, arrow function)
So you must use Node.js v6.4.0 or more.$3
* global (recommended)
`bash
npm i -g perf-chk
`
* local
`bash
npm i -D perf-chk
`$3
#### 1. make your test code. (module)
`javascript
// some code
// blahblahmodule.exports = {
methodA: function() { // ES5 function syntax
// blahblah
},
methodB() { // ES6 Method syntax
// blahblah
},
methodC: () => { // ES6 Arrow Function syntax
// blahblah
}
}
`
##### note
* module.exports = {} is module export syntax in node.js.
and perf-chk is node.js app, so you must use this syntax.
* You can choose function syntax #### 2. check execution time
1. open terminal(cmd in windows)
2. type below,
`bash
perf-chk {module_name} [iteration_counts]
`
If you installed it locally, type below
`bash
./node_modules/perf-chk {module_name} [iteration_counts]
``##### note
module_name is required, and module_name is \
iteration_counts is optional, default value is 100,000,000.
iteration_counts range is safe integer for natural number.
range is 1 ~ 9,007,199,254,740,991.
if the execution time of functions are similar,
There is no difference between them,
but you want to know diffrence of execution time,
you have to extend iteration_counts