diff --git a/dist/early.hrtMeasurement.d.ts b/dist/early.hrtMeasurement.d.ts new file mode 100644 index 0000000..02093d9 --- /dev/null +++ b/dist/early.hrtMeasurement.d.ts @@ -0,0 +1,22 @@ +/** + * easy high resolution time measurement + */ +export declare class HrtMeasurement { + nanoSeconds: number; + milliSeconds: number; + private _hrTimeStart; + private _hrTimeStopDiff; + private _started; + /** + * start the measurement + */ + start(): void; + /** + * stop the measurement + */ + stop(): this; + /** + * reset the measurement + */ + reset(): void; +} diff --git a/dist/early.hrtMeasurement.js b/dist/early.hrtMeasurement.js new file mode 100644 index 0000000..d045503 --- /dev/null +++ b/dist/early.hrtMeasurement.js @@ -0,0 +1,47 @@ +"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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZWFybHkuaHJ0TWVhc3VyZW1lbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9lYXJseS5ocnRNZWFzdXJlbWVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLG1DQUFrQztBQUVsQzs7R0FFRztBQ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BSSxDQUFBO1FBQ3hCLElBQUksQ0FBQyxZQUFZLEdBQUcsSUFBSSxDQUFBO1FBQ3hCLElBQUksQ0FBQyxlQUFlLEdBQUcsSUFBSSxDQUFBO1FBQzNCLElBQUksQ0FBQyxRQUFRLEdBQUcsS0FBSyxDQUFBO0lBQ3ZCLENBQUM7Q0FDRjtBQXZDRCx3Q0F1Q0MifQ== \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts index 9487760..287b635 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,15 +1,8 @@ import 'typings-global'; +import { HrtMeasurement } from './early.hrtMeasurement'; +export { HrtMeasurement }; /** * start the loading */ export declare let start: (moduleNameArg?: string, loaderLengthArg?: string) => void; export declare let stop: () => Promise; -export declare class hrtMeasurement { - private _started; - private _hrTimeStart; - start(): void; - stop(): { - nanoSeconds: number; - milliSeconds: number; - }; -} diff --git a/dist/index.js b/dist/index.js index f46ece4..c3a8f6c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); require("typings-global"); const beautycolor = require("beautycolor"); const smartq = require("smartq"); -const process = require("process"); +const early_hrtMeasurement_1 = require("./early.hrtMeasurement"); +exports.HrtMeasurement = early_hrtMeasurement_1.HrtMeasurement; let doText = false; let moduleName = 'undefined module name'; -let startTime = Date.now(); +let startHrt; if (process.argv.indexOf('-v') === -1) { doText = true; } @@ -15,40 +16,18 @@ if (process.argv.indexOf('-v') === -1) { */ exports.start = function (moduleNameArg = '', loaderLengthArg = '10') { moduleName = moduleNameArg; + startHrt = new early_hrtMeasurement_1.HrtMeasurement(); + startHrt.start(); if (doText) { console.log(`**** starting ${beautycolor.coloredString(moduleNameArg, 'green')} ****`); } }; exports.stop = () => { let done = smartq.defer(); - let endTime = Date.now(); - let earlyExecutionTime = (endTime - startTime); + let earlyExecutionTime = startHrt.stop().milliSeconds; let earlyExecutionTimeString = (earlyExecutionTime / 1000).toString(); console.log(`OK! -> finished loading within ${beautycolor.coloredString(earlyExecutionTimeString, 'blue')}`); done.resolve(earlyExecutionTime); return done.promise; }; -class hrtMeasurement { - constructor() { - this._started = false; - } - start() { - this._started = true; - this._hrTimeStart = process.hrtime(); - } - stop() { - if (this._started === false) { - console.log('Hasn\'t started yet'); - return; - } - let diffTime = process.hrtime(this._hrTimeStart); - let nanoSeconds = (diffTime[0] * 1e9) + diffTime[1]; - let milliSeconds = nanoSeconds / 1000000; - return { - nanoSeconds: nanoSeconds, - milliSeconds: milliSeconds - }; - } -} -exports.hrtMeasurement = hrtMeasurement; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QiwyQ0FBMEM7QUFDMUMsaUNBQWdDO0FBQ2hDLG1DQUFrQztBQUVsQyxJQUFJLE1BQU0sR0FBWSxLQUFLLENBQUE7QUFDM0IsSUFBSSxVQUFVLEdBQVcsdUJBQXVCLENBQUE7QUFDaEQsSUFBSSxTQUFTLEdBQUcsSUFBSSxDQUFDLEdBQUcsRUFBRSxDQUFBO0FBRTFCLEVBQUUsQ0FBQyxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUN0QyxNQUFNLEdBQUcsSUFBSSxDQUFBO0FBQ2YsQ0FBQztBQUVEOztHQUVHO0FBQ1EsUUFBQSxLQUFLLEdBQUcsVUFBVSxnQkFBd0IsRUFBRSxFQUFFLGtCQUEwQixJQUFJO0lBQ3JGLFVBQVUsR0FBRyxhQUFhLENBQUE7SUFDMUIsRUFBRSxDQUFDLENBQUMsTUFBTSxDQUFDLENBQUMsQ0FBQztRQUNYLE9BQU8sQ0FBQyx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QUFFLEVBQUUsa0JBQTBCLElBQUk7SUFDckYsVUFBVSxHQUFHLGFBQWEsQ0FBQTtJQUMxQixRQUFRLEdBQUcsSUFBSSxxQ0FBYyxFQUFFLENBQUE7SUFDL0IsUUFBUSxDQUFDLEtBQUssRUFBRSxDQUFBO0lBQ2hCLEVBQUUsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUM7UUFDWCxPQUFPLENBQUMsR0FBRyxDQUFDLGlCQUFpQixXQUFXLENBQUMsYUFBYSxDQUFDLGFBQWEsRUFBRSxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUE7SUFDeEYsQ0FBQztBQUNILENBQUMsQ0FBQTtBQUVVLFFBQUEsSUFBSSxHQUFHO0lBQ2hCLElBQUksSUFBSSxHQUFHLE1BQU0sQ0FBQyxLQUFLLEVBQVUsQ0FBQTtJQUNqQyxJQUFJLGtCQUFrQixHQUFHLFFBQVEsQ0FBQyxJQUFJLEVBQUUsQ0FBQyxZQUFZLENBQUE7SUFDckQsSUFBSSx3QkFBd0IsR0FBVyxDQUFDLGtCQUFrQixHQUFHLElBQUksQ0FBQyxDQUFDLFFBQVEsRUFBRSxDQUFBO0lBQzdFLE9BQU8sQ0FBQyxHQUFHLENBQUMsa0NBQWtDLFdBQVcsQ0FBQyxhQUFhLENBQUMsd0JBQXdCLEVBQUUsTUFBTSxDQUFDLEVBQUUsQ0FBQyxDQUFBO0lBQzVHLElBQUksQ0FBQyxPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0FBQTtJQUNoQyxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtBQUNyQixDQUFDLENBQUEifQ== \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index 90629a2..3d42bc5 100644 --- a/test/test.ts +++ b/test/test.ts @@ -12,7 +12,7 @@ tap.test('.stop()', async () => { }) tap.test('hrTime Measurement', async () => { - let earlyHr = new early.hrtMeasurement() + let earlyHr = new early.HrtMeasurement() earlyHr.start() await smartdelay.delayFor(1000) let measuredTime = earlyHr.stop() diff --git a/ts/early.hrtMeasurement.ts b/ts/early.hrtMeasurement.ts new file mode 100644 index 0000000..e421710 --- /dev/null +++ b/ts/early.hrtMeasurement.ts @@ -0,0 +1,45 @@ +import * as process from 'process' + +/** + * easy high resolution time measurement + */ +export class HrtMeasurement { + nanoSeconds: number = null + milliSeconds: number = null + private _hrTimeStart = null + private _hrTimeStopDiff = null + private _started: boolean = 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 + } +} diff --git a/ts/index.ts b/ts/index.ts index 8359649..b9a1498 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,11 +1,15 @@ import 'typings-global' import * as beautycolor from 'beautycolor' import * as smartq from 'smartq' -import * as process from 'process' +import { HrtMeasurement } from './early.hrtMeasurement' + +export { + HrtMeasurement +} let doText: boolean = false let moduleName: string = 'undefined module name' -let startTime = Date.now() +let startHrt: HrtMeasurement if (process.argv.indexOf('-v') === -1) { doText = true @@ -16,6 +20,8 @@ if (process.argv.indexOf('-v') === -1) { */ export let start = function (moduleNameArg: string = '', loaderLengthArg: string = '10') { moduleName = moduleNameArg + startHrt = new HrtMeasurement() + startHrt.start() if (doText) { console.log(`**** starting ${beautycolor.coloredString(moduleNameArg, 'green')} ****`) } @@ -23,32 +29,9 @@ export let start = function (moduleNameArg: string = '', loaderLengthArg: string export let stop = (): Promise => { let done = smartq.defer() - let endTime = Date.now() - let earlyExecutionTime: number = (endTime - startTime) + let earlyExecutionTime = startHrt.stop().milliSeconds let earlyExecutionTimeString: string = (earlyExecutionTime / 1000).toString() console.log(`OK! -> finished loading within ${beautycolor.coloredString(earlyExecutionTimeString, 'blue')}`) done.resolve(earlyExecutionTime) return done.promise } - -export class hrtMeasurement { - private _started: boolean = false - private _hrTimeStart - start () { - this._started = true - this._hrTimeStart = process.hrtime() - } - stop () { - if (this._started === false) { - console.log('Hasn\'t started yet') - return - } - let diffTime = process.hrtime(this._hrTimeStart) - let nanoSeconds = (diffTime[0] * 1e9) + diffTime[1] - let milliSeconds = nanoSeconds / 1000000 - return { - nanoSeconds: nanoSeconds, - milliSeconds: milliSeconds - } - } -}