now has hrtime Measurement

This commit is contained in:
Philipp Kunz 2017-04-23 18:46:13 +02:00
parent 836f8d18b0
commit fad367ca0b
6 changed files with 121 additions and 1546 deletions

9
dist/index.d.ts vendored
View File

@ -4,3 +4,12 @@ import 'typings-global';
*/ */
export declare let start: (moduleNameArg?: string, loaderLengthArg?: string) => void; export declare let start: (moduleNameArg?: string, loaderLengthArg?: string) => void;
export declare let stop: () => Promise<number>; export declare let stop: () => Promise<number>;
export declare class hrtMeasurement {
private _started;
private _hrTimeStart;
start(): void;
stop(): {
nanoSeconds: number;
milliSeconds: number;
};
}

26
dist/index.js vendored
View File

@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global"); require("typings-global");
const beautycolor = require("beautycolor"); const beautycolor = require("beautycolor");
const smartq = require("smartq"); const smartq = require("smartq");
const process = require("process");
let doText = false; let doText = false;
let moduleName = 'undefined module name'; let moduleName = 'undefined module name';
let startTime = Date.now(); let startTime = Date.now();
@ -27,4 +28,27 @@ exports.stop = () => {
done.resolve(earlyExecutionTime); done.resolve(earlyExecutionTime);
return done.promise; return done.promise;
}; };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QiwyQ0FBMEM7QUFDMUMsaUNBQWdDO0FBRWhDLElBQUksTUFBTSxHQUFZLEtBQUssQ0FBQTtBQUMzQixJQUFJLFVBQVUsR0FBVyx1QkFBdUIsQ0FBQTtBQUNoRCxJQUFJLFNBQVMsR0FBRyxJQUFJLENBQUMsR0FBRyxFQUFFLENBQUE7QUFFMUIsRUFBRSxDQUFDLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDO0lBQ3RDLE1BQU0sR0FBRyxJQUFJLENBQUE7QUFDZixDQUFDO0FBRUQ7O0dBRUc7QUFDUSxRQUFBLEtBQUssR0FBRyxVQUFVLGdCQUF3QixFQUFFLEVBQUUsa0JBQTBCLElBQUk7SUFDckYsVUFBVSxHQUFHLGFBQWEsQ0FBQTtJQUMxQixFQUFFLENBQUMsQ0FBQyxNQUFNLENBQUMsQ0FBQyxDQUFDO1FBQ1gsT0FBTyxDQUFDLEdBQUcsQ0FBQyxpQkFBaUIsV0FBVyxDQUFDLGFBQWEsQ0FBQyxhQUFhLEVBQUUsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUFBO0lBQ3hGLENBQUM7QUFDSCxDQUFDLENBQUE7QUFFVSxRQUFBLElBQUksR0FBRztJQUNoQixJQUFJLElBQUksR0FBRyxNQUFNLENBQUMsS0FBSyxFQUFVLENBQUE7SUFDakMsSUFBSSxPQUFPLEdBQUcsSUFBSSxDQUFDLEdBQUcsRUFBRSxDQUFBO0lBQ3hCLElBQUksa0JBQWtCLEdBQVcsQ0FBQyxPQUFPLEdBQUcsU0FBUyxDQUFDLENBQUE7SUFDdEQsSUFBSSx3QkFBd0IsR0FBVyxDQUFDLGtCQUFrQixHQUFHLElBQUksQ0FBQyxDQUFDLFFBQVEsRUFBRSxDQUFBO0lBQzdFLE9BQU8sQ0FBQyxHQUFHLENBQUMsa0NBQWtDLFdBQVcsQ0FBQyxhQUFhLENBQUMsd0JBQXdCLEVBQUUsTUFBTSxDQUFDLEVBQUUsQ0FBQyxDQUFBO0lBQzVHLElBQUksQ0FBQyxPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0FBQTtJQUNoQyxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtBQUNyQixDQUFDLENBQUEifQ== 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QiwyQ0FBMEM7QUFDMUMsaUNBQWdDO0FBQ2hDLG1DQUFrQztBQUVsQyxJQUFJLE1BQU0sR0FBWSxLQUFLLENBQUE7QUFDM0IsSUFBSSxVQUFVLEdBQVcsdUJBQXVCLENBQUE7QUFDaEQsSUFBSSxTQUFTLEdBQUcsSUFBSSxDQUFDLEdBQUcsRUFBRSxDQUFBO0FBRTFCLEVBQUUsQ0FBQyxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUN0QyxNQUFNLEdBQUcsSUFBSSxDQUFBO0FBQ2YsQ0FBQztBQUVEOztHQUVHO0FBQ1EsUUFBQSxLQUFLLEdBQUcsVUFBVSxnQkFBd0IsRUFBRSxFQUFFLGtCQUEwQixJQUFJO0lBQ3JGLFVBQVUsR0FBRyxhQUFhLENBQUE7SUFDMUIsRUFBRSxDQUFDLENBQUMsTUFBTSxDQUFDLENBQUMsQ0FBQztRQUNYLE9BQU8sQ0FBQyxHQUFHLENBQUMsaUJBQWlCLFdBQVcsQ0FBQyxhQUFhLENBQUMsYUFBYSxFQUFFLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FBQTtJQUN4RixDQUFDO0FBQ0gsQ0FBQyxDQUFBO0FBRVUsUUFBQSxJQUFJLEdBQUc7SUFDaE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RQUFRLENBQUMsQ0FBQyxDQUFDLEdBQUcsR0FBRyxDQUFDLEdBQUcsUUFBUSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQ25ELElBQUksWUFBWSxHQUFHLFdBQVcsR0FBRyxPQUFPLENBQUE7UUFDeEMsTUFBTSxDQUFDO1lBQ0wsV0FBVyxFQUFFLFdBQVc7WUFDeEIsWUFBWSxFQUFFLFlBQVk7U0FDM0IsQ0FBQTtJQUNILENBQUM7Q0FDRjtBQXBCRCx3Q0FvQkMifQ==

View File

@ -22,11 +22,11 @@
"homepage": "https://gitlab.com/pushrocks/early#readme", "homepage": "https://gitlab.com/pushrocks/early#readme",
"devDependencies": { "devDependencies": {
"smartdelay": "^1.0.1", "smartdelay": "^1.0.1",
"tapbundle": "^1.0.5" "tapbundle": "^1.0.8"
}, },
"dependencies": { "dependencies": {
"beautycolor": "^1.0.7", "beautycolor": "^1.0.7",
"smartq": "^1.1.1", "smartq": "^1.1.1",
"typings-global": "^1.0.14" "typings-global": "^1.0.16"
} }
} }

View File

@ -6,6 +6,18 @@ tap.test('.start()', async () => {
early.start('early') early.start('early')
await smartdelay.delayFor(2000) await smartdelay.delayFor(2000)
}) })
tap.test('.stop()', async () => { tap.test('.stop()', async () => {
await early.stop() await early.stop()
}) })
tap.test('hrTime Measurement', async () => {
let earlyHr = new early.hrtMeasurement()
earlyHr.start()
await smartdelay.delayFor(1000)
let measuredTime = earlyHr.stop()
console.log(measuredTime)
return expect(measuredTime.milliSeconds).to.be.greaterThan(999)
})
tap.start()

View File

@ -1,6 +1,7 @@
import 'typings-global' import 'typings-global'
import * as beautycolor from 'beautycolor' import * as beautycolor from 'beautycolor'
import * as smartq from 'smartq' import * as smartq from 'smartq'
import * as process from 'process'
let doText: boolean = false let doText: boolean = false
let moduleName: string = 'undefined module name' let moduleName: string = 'undefined module name'
@ -29,3 +30,25 @@ export let stop = (): Promise<number> => {
done.resolve(earlyExecutionTime) done.resolve(earlyExecutionTime)
return done.promise 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
}
}
}

1591
yarn.lock

File diff suppressed because it is too large Load Diff