now has better hrtMeasurement

This commit is contained in:
Philipp Kunz 2017-04-23 20:57:01 +02:00
parent fad367ca0b
commit 270cb2533e
7 changed files with 133 additions and 64 deletions

22
dist/early.hrtMeasurement.d.ts vendored Normal file
View File

@ -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;
}

47
dist/early.hrtMeasurement.js vendored Normal file
View File

@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZWFybHkuaHJ0TWVhc3VyZW1lbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9lYXJseS5ocnRNZWFzdXJlbWVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLG1DQUFrQztBQUVsQzs7R0FFRztBQUNIO0lBQUE7UUFDRSxnQkFBVyxHQUFXLElBQUksQ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dBQUcsSUFBSSxDQUFBO1FBQ3hCLElBQUksQ0FBQyxlQUFlLEdBQUcsSUFBSSxDQUFBO1FBQzNCLElBQUksQ0FBQyxRQUFRLEdBQUcsS0FBSyxDQUFBO0lBQ3ZCLENBQUM7Q0FDRjtBQXZDRCx3Q0F1Q0MifQ==

11
dist/index.d.ts vendored
View File

@ -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<number>;
export declare class hrtMeasurement {
private _started;
private _hrTimeStart;
start(): void;
stop(): {
nanoSeconds: number;
milliSeconds: number;
};
}

35
dist/index.js vendored
View File

@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QiwyQ0FBMEM7QUFDMUMsaUNBQWdDO0FBQ2hDLG1DQUFrQztBQUVsQyxJQUFJLE1BQU0sR0FBWSxLQUFLLENBQUE7QUFDM0IsSUFBSSxVQUFVLEdBQVcsdUJBQXVCLENBQUE7QUFDaEQsSUFBSSxTQUFTLEdBQUcsSUFBSSxDQUFDLEdBQUcsRUFBRSxDQUFBO0FBRTFCLEVBQUUsQ0FBQyxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUN0QyxNQUFNLEdBQUcsSUFBSSxDQUFBO0FBQ2YsQ0FBQztBQUVEOztHQUVHO0FBQ1EsUUFBQSxLQUFLLEdBQUcsVUFBVSxnQkFBd0IsRUFBRSxFQUFFLGtCQUEwQixJQUFJO0lBQ3JGLFVBQVUsR0FBRyxhQUFhLENBQUE7SUFDMUIsRUFBRSxDQUFDLENBQUMsTUFBTSxDQUFDLENBQUMsQ0FBQztRQUNYLE9BQU8sQ0FBQyxHQUFHLENBQUMsaUJBQWlCLFdBQVcsQ0FBQyxhQUFhLENBQUMsYUFBYSxFQUFFLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FBQTtJQUN4RixDQUFDO0FBQ0gsQ0FBQyxDQUFBO0F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SxDQUFBO0lBQ2hCLEVBQUUsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUM7UUFDWCxPQUFPLENBQUMsR0FBRyxDQUFDLGlCQUFpQixXQUFXLENBQUMsYUFBYSxDQUFDLGFBQWEsRUFBRSxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUE7SUFDeEYsQ0FBQztBQUNILENBQUMsQ0FBQTtBQUVVLFFBQUEsSUFBSSxHQUFHO0lBQ2hCLElBQUksSUFBSSxHQUFHLE1BQU0sQ0FBQyxLQUFLLEVBQVUsQ0FBQTtJQUNqQyxJQUFJLGtCQUFrQixHQUFHLFFBQVEsQ0FBQyxJQUFJLEVBQUUsQ0FBQyxZQUFZLENBQUE7SUFDckQsSUFBSSx3QkFBd0IsR0FBVyxDQUFDLGtCQUFrQixHQUFHLElBQUksQ0FBQyxDQUFDLFFBQVEsRUFBRSxDQUFBO0lBQzdFLE9BQU8sQ0FBQyxHQUFHLENBQUMsa0NBQWtDLFdBQVcsQ0FBQyxhQUFhLENBQUMsd0JBQXdCLEVBQUUsTUFBTSxDQUFDLEVBQUUsQ0FBQyxDQUFBO0lBQzVHLElBQUksQ0FBQyxPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0FBQTtJQUNoQyxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtBQUNyQixDQUFDLENBQUEifQ==

View File

@ -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()

View File

@ -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
}
}

View File

@ -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<number> => {
let done = smartq.defer<number>()
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
}
}
}