@foxpage/foxpage-node-sdk
Version:
foxpage node sdk
37 lines (36 loc) • 767 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.timeEnd = exports.timeStart = void 0;
const timerMap = new Map();
/**
* cost start
* @param label
* @returns
*/
const timeStart = (label, cb) => {
const time = +new Date();
timerMap.set(label, time);
return () => {
return (0, exports.timeEnd)(label, cb);
};
};
exports.timeStart = timeStart;
/**
* cost end
* @param label
* @returns
*/
const timeEnd = (label, cb) => {
let cost = -1;
const start = timerMap.get(label);
if (start) {
const now = +new Date();
cost = now - start;
timerMap.delete(label);
}
if (typeof cb === 'function') {
cb(cost);
}
return cost;
};
exports.timeEnd = timeEnd;