@strapi/strapi
Version:
An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite
31 lines (28 loc) • 830 B
JavaScript
import { performance } from 'perf_hooks';
function getTimer() {
const timings = {};
const startTimes = {};
function start(name) {
if (typeof startTimes[name] !== 'undefined') {
throw new Error(`Timer "${name}" already started, cannot overwrite`);
}
startTimes[name] = performance.now();
}
function end(name) {
if (typeof startTimes[name] === 'undefined') {
throw new Error(`Timer "${name}" never started, cannot end`);
}
timings[name] = performance.now() - startTimes[name];
return timings[name];
}
return {
start,
end,
getTimings: ()=>timings
};
}
const prettyTime = (timeInMs)=>{
return `${Math.ceil(timeInMs)}ms`;
};
export { getTimer, prettyTime };
//# sourceMappingURL=timer.mjs.map