an easy way to benchmark your javascript code
npm install --save-dev babel-plugin-jsperf
.babelrc
{
"plugins": ["jsperf"]
}
babel --plugins jsperf code.js -o out.js
// jsperf
function todo() {
console.log('toto');
}
↓ ↓ ↓ ↓ ↓ ↓
// jsperf
function todo() {
console.time('todo');
console.log('toto');
console.timeEnd('todo');
}
const foo = /* jsperf */ () => 'test';
↓ ↓ ↓ ↓ ↓ ↓
const foo = /* jsperf */function () {
console.time('foo');
var _returnValue = 'test';
console.timeEnd('foo');
return _returnValue;
};
class clazz {
// jsperf
method() {
console.log('class method !');
}
}
↓ ↓ ↓ ↓ ↓ ↓
class clazz {
// jsperf
method() {
console.time('function2');
console.log('class method !');
console.timeEnd('function2');
}
}
// jsperf
function foo() {
const bar = 'bar';
return bar;
}
↓ ↓ ↓ ↓ ↓ ↓
// jsperf
function foo() {
console.time('foo');
const bar = 'bar';
var _returnValue = bar;
console.timeEnd('foo');
return _returnValue;
}