47 lines
2.7 KiB
JavaScript
47 lines
2.7 KiB
JavaScript
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
const process = require("process");
|
||
|
/**
|
||
|
* easy high resolution time measurement
|
||
|
*/
|
||
|
class HrtMeasurement {
|
||
|
constructor() {
|
||
|
this.nanoSeconds = null;
|
||
|
this.milliSeconds = null;
|
||
|
this._hrTimeStart = null;
|
||
|
this._hrTimeStopDiff = null;
|
||
|
this._started = false;
|
||
|
}
|
||
|
/**
|
||
|
* start the measurement
|
||
|
*/
|
||
|
start() {
|
||
|
this._started = true;
|
||
|
this._hrTimeStart = process.hrtime();
|
||
|
}
|
||
|
/**
|
||
|
* stop the measurement
|
||
|
*/
|
||
|
stop() {
|
||
|
if (this._started === false) {
|
||
|
console.log('Hasn\'t started yet');
|
||
|
return;
|
||
|
}
|
||
|
this._hrTimeStopDiff = process.hrtime(this._hrTimeStart);
|
||
|
this.nanoSeconds = (this._hrTimeStopDiff[0] * 1e9) + this._hrTimeStopDiff[1];
|
||
|
this.milliSeconds = this.nanoSeconds / 1000000;
|
||
|
return this;
|
||
|
}
|
||
|
/**
|
||
|
* reset the measurement
|
||
|
*/
|
||
|
reset() {
|
||
|
this.nanoSeconds = null;
|
||
|
this.milliSeconds = null;
|
||
|
this._hrTimeStart = null;
|
||
|
this._hrTimeStopDiff = null;
|
||
|
this._started = false;
|
||
|
}
|
||
|
}
|
||
|
exports.HrtMeasurement = HrtMeasurement;
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR0aW1lLmNsYXNzZXMuaHJ0bWVhc3VyZW1lbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHRpbWUuY2xhc3Nlcy5ocnRtZWFzdXJlbWVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLG1DQUFrQztBQUVsQzs7R0FFRztBQUNIO0lBQUE7UU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