@liqd-js/mongodb-model
Version:
Mongo model class
31 lines (30 loc) • 1.02 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Benchmark = exports.formatter = void 0;
exports.formatter = new Intl.DateTimeFormat('en-US', { hour: 'numeric', minute: 'numeric', second: 'numeric', fractionalSecondDigits: 3, hour12: false });
class Benchmark {
name;
start = new Date();
last = Date.now();
constructor(name) {
this.name = name;
}
elapsed() {
return Date.now() - this.start.getTime();
}
step(label) {
const now = Date.now(), step = now - this.last;
this.last = now;
console.log(`[BMARK:${exports.formatter.format(new Date())}] ${this.name} step ${label} in ${step}ms)`);
}
get startTime() {
return exports.formatter.format(this.start);
}
get time() {
return exports.formatter.format(new Date());
}
end() {
console.log(`[BMARK:${exports.formatter.format(new Date())}] ${this.name} ended in ${this.elapsed()}ms)`);
}
}
exports.Benchmark = Benchmark;
;