ブラウザのConsoleで下記の結果が確認できます。
function perform(start, end) {
if (arguments.length === 1) {
performance.mark(start);
} else if (arguments.length === 2) {
performance.mark(end);
performance.measure('_' + start, start, end);
console.log(
start + ' 〜 ' + end + ': ' +
Math.floor(performance.getEntriesByName('_' + start)[0].duration) + 'ms'
);
} else {
throw new Error('arguments can set 1 or 2');
}
}
// 計測開始
perform('myStart');
setTimeout(function() {
// 計測終了
perform('myStart', 'myEnd');
}, 1000);