Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
ce99e04b45 | |||
c0a1e0a14f | |||
83392d18f6 | |||
270cb2533e | |||
fad367ca0b | |||
836f8d18b0 | |||
ce269ae337 |
@ -60,7 +60,7 @@ pages:
|
|||||||
stage: pages
|
stage: pages
|
||||||
script:
|
script:
|
||||||
- npmci command yarn global add npmpage
|
- npmci command yarn global add npmpage
|
||||||
- npmci command npmpage --publish gitlab
|
- npmci command npmpage
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
only:
|
only:
|
||||||
|
15
README.md
15
README.md
@ -18,21 +18,6 @@ minimal and fast loading plugin for startup time measuring
|
|||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
[](http://standardjs.com/)
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
## Usage
|
|
||||||
Use TypeScript for best in class instellisense.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// Put the following at the start of your module
|
|
||||||
import * as early from "early";
|
|
||||||
early.start("myModuleName");
|
|
||||||
/*
|
|
||||||
do your loading stuff
|
|
||||||
*/
|
|
||||||
early.stop().then((loadingTime:number) => { // loadingTime in milliseconds
|
|
||||||
|
|
||||||
}); // stop "early" when your module is ready
|
|
||||||
```
|
|
||||||
|
|
||||||
For further information read the linked docs at the top of this README.
|
For further information read the linked docs at the top of this README.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
22
dist/early.hrtMeasurement.d.ts
vendored
Normal file
22
dist/early.hrtMeasurement.d.ts
vendored
Normal 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
47
dist/early.hrtMeasurement.js
vendored
Normal 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZWFybHkuaHJ0TWVhc3VyZW1lbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9lYXJseS5ocnRNZWFzdXJlbWVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLG1DQUFrQztBQUVsQzs7R0FFRztBQUNIO0lBQUE7UUFDRSxnQkFBVyxHQUFXLElBQUksQ0FBQTtRQUMxQixpQkFBWSxHQUFXLElBQUksQ0FBQTtRQUNuQixpQkFBWSxHQUFHLElBQUksQ0FBQTtRQUNuQixvQkFBZSxHQUFHLElBQUksQ0FBQTtRQUN0QixhQUFRLEdBQVksS0FBSyxDQUFBO0lBa0NuQyxDQUFDO0lBaENDOztPQUVHO0lBQ0gsS0FBSztRQUNILElBQUksQ0FBQyxRQUFRLEdBQUcsSUFBSSxDQUFBO1FBQ3BCLElBQUksQ0FBQyxZQUFZLEdBQUcsT0FBTyxDQUFDLE1BQU0sRUFBRSxDQUFBO0lBQ3RDLENBQUM7SUFFRDs7T0FFRztJQUNILElBQUk7UUFDRixFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsUUFBUSxLQUFLLEtBQUssQ0FBQyxDQUFDLENBQUM7WUFDNUIsT0FBTyxDQUFDLEdBQUcsQ0FBQyxxQkFBcUIsQ0FBQyxDQUFBO1lBQ2xDLE1BQU0sQ0FBQTtRQUNSLENBQUM7UUFDRCxJQUFJLENBQUMsZUFBZSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLFlBQVksQ0FBQyxDQUFBO1FBQ3hELElBQUksQ0FBQyxXQUFXLEdBQUcsQ0FBQyxJQUFJLENBQUMsZUFBZSxDQUFDLENBQUMsQ0FBQyxHQUFHLEdBQUcsQ0FBQyxHQUFHLElBQUksQ0FBQyxlQUFlLENBQUMsQ0FBQyxDQUFDLENBQUE7UUFDNUUsSUFBSSxDQUFDLFlBQVksR0FBRyxJQUFJLENBQUMsV0FBVyxHQUFHLE9BQU8sQ0FBQTtRQUM5QyxNQUFNLENBQUMsSUFBSSxDQUFBO0lBQ2IsQ0FBQztJQUVEOztPQUVHO0lBQ0gsS0FBSztRQUNILElBQUksQ0FBQyxXQUFXLEdBQUcsSUFBSSxDQUFBO1FBQ3ZCLElBQUksQ0FBQyxZQUFZLEdBQUcsSUFBSSxDQUFBO1FBQ3hCLElBQUksQ0FBQyxZQUFZLEdBQUcsSUFBSSxDQUFBO1FBQ3hCLElBQUksQ0FBQyxlQUFlLEdBQUcsSUFBSSxDQUFBO1FBQzNCLElBQUksQ0FBQyxRQUFRLEdBQUcsS0FBSyxDQUFBO0lBQ3ZCLENBQUM7Q0FDRjtBQXZDRCx3Q0F1Q0MifQ==
|
2
dist/index.d.ts
vendored
2
dist/index.d.ts
vendored
@ -1,4 +1,6 @@
|
|||||||
import 'typings-global';
|
import 'typings-global';
|
||||||
|
import { HrtMeasurement } from './early.hrtMeasurement';
|
||||||
|
export { HrtMeasurement };
|
||||||
/**
|
/**
|
||||||
* start the loading
|
* start the loading
|
||||||
*/
|
*/
|
||||||
|
11
dist/index.js
vendored
11
dist/index.js
vendored
@ -3,9 +3,11 @@ 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 early_hrtMeasurement_1 = require("./early.hrtMeasurement");
|
||||||
|
exports.HrtMeasurement = early_hrtMeasurement_1.HrtMeasurement;
|
||||||
let doText = false;
|
let doText = false;
|
||||||
let moduleName = 'undefined module name';
|
let moduleName = 'undefined module name';
|
||||||
let startTime = Date.now();
|
let startHrt;
|
||||||
if (process.argv.indexOf('-v') === -1) {
|
if (process.argv.indexOf('-v') === -1) {
|
||||||
doText = true;
|
doText = true;
|
||||||
}
|
}
|
||||||
@ -14,17 +16,18 @@ if (process.argv.indexOf('-v') === -1) {
|
|||||||
*/
|
*/
|
||||||
exports.start = function (moduleNameArg = '', loaderLengthArg = '10') {
|
exports.start = function (moduleNameArg = '', loaderLengthArg = '10') {
|
||||||
moduleName = moduleNameArg;
|
moduleName = moduleNameArg;
|
||||||
|
startHrt = new early_hrtMeasurement_1.HrtMeasurement();
|
||||||
|
startHrt.start();
|
||||||
if (doText) {
|
if (doText) {
|
||||||
console.log(`**** starting ${beautycolor.coloredString(moduleNameArg, 'green')} ****`);
|
console.log(`**** starting ${beautycolor.coloredString(moduleNameArg, 'green')} ****`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
exports.stop = () => {
|
exports.stop = () => {
|
||||||
let done = smartq.defer();
|
let done = smartq.defer();
|
||||||
let endTime = Date.now();
|
let earlyExecutionTime = startHrt.stop().milliSeconds;
|
||||||
let earlyExecutionTime = (endTime - startTime);
|
|
||||||
let earlyExecutionTimeString = (earlyExecutionTime / 1000).toString();
|
let earlyExecutionTimeString = (earlyExecutionTime / 1000).toString();
|
||||||
console.log(`OK! -> finished loading within ${beautycolor.coloredString(earlyExecutionTimeString, 'blue')}`);
|
console.log(`OK! -> finished loading within ${beautycolor.coloredString(earlyExecutionTimeString, 'blue')}`);
|
||||||
done.resolve(earlyExecutionTime);
|
done.resolve(earlyExecutionTime);
|
||||||
return done.promise;
|
return done.promise;
|
||||||
};
|
};
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QiwyQ0FBMEM7QUFDMUMsaUNBQWdDO0FBRWhDLElBQUksTUFBTSxHQUFZLEtBQUss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UE7SUFDeEYsQ0FBQztBQUNILENBQUMsQ0FBQTtBQUVVLFFBQUEsSUFBSSxHQUFHO0lBQ2hCLElBQUksSUFBSSxHQUFHLE1BQU0sQ0FBQyxLQUFLLEVBQVUsQ0FBQTtJQUNqQyxJQUFJLGtCQUFrQixHQUFHLFFBQVEsQ0FBQyxJQUFJLEVBQUUsQ0FBQyxZQUFZLENBQUE7SUFDckQsSUFBSSx3QkFBd0IsR0FBVyxDQUFDLGtCQUFrQixHQUFHLElBQUksQ0FBQyxDQUFDLFFBQVEsRUFBRSxDQUFBO0lBQzdFLE9BQU8sQ0FBQyxHQUFHLENBQUMsa0NBQWtDLFdBQVcsQ0FBQyxhQUFhLENBQUMsd0JBQXdCLEVBQUUsTUFBTSxDQUFDLEVBQUUsQ0FBQyxDQUFBO0lBQzVHLElBQUksQ0FBQyxPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0FBQTtJQUNoQyxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtBQUNyQixDQUFDLENBQUEifQ==
|
40
docs/index.md
Normal file
40
docs/index.md
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
# early
|
||||||
|
minimal and fast loading plugin for startup time measuring
|
||||||
|
|
||||||
|
## Availabililty
|
||||||
|
[](https://www.npmjs.com/package/early)
|
||||||
|
[](https://GitLab.com/pushrocks/early)
|
||||||
|
[](https://github.com/pushrocks/early)
|
||||||
|
[](https://pushrocks.gitlab.io/early/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
[](https://GitLab.com/pushrocks/early/commits/master)
|
||||||
|
[](https://GitLab.com/pushrocks/early/commits/master)
|
||||||
|
[](https://www.npmjs.com/package/early)
|
||||||
|
[](https://david-dm.org/pushrocks/early)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/early/master/dependencies/npm)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/early)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Put the following at the start of your module
|
||||||
|
import * as early from "early";
|
||||||
|
early.start("myModuleName");
|
||||||
|
/*
|
||||||
|
do your loading stuff
|
||||||
|
*/
|
||||||
|
early.stop().then((loadingTime:number) => { // loadingTime in milliseconds
|
||||||
|
|
||||||
|
}); // stop "early" when your module is ready
|
||||||
|
```
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this README.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
|
||||||
|
[](https://push.rocks)
|
@ -1,5 +1,10 @@
|
|||||||
{
|
{
|
||||||
"npmts":{
|
"npmts":{
|
||||||
"coverageTreshold":50
|
"coverageTreshold":50
|
||||||
|
},
|
||||||
|
"npmci": {
|
||||||
|
"globalNpmTools": [
|
||||||
|
"npmts"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "early",
|
"name": "early",
|
||||||
"version": "2.0.37",
|
"version": "2.1.1",
|
||||||
"description": "minimal and fast loading plugin for startup time measuring",
|
"description": "minimal and fast loading plugin for startup time measuring",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
test/test.ts
14
test/test.ts
@ -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()
|
||||||
|
45
ts/early.hrtMeasurement.ts
Normal file
45
ts/early.hrtMeasurement.ts
Normal 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
|
||||||
|
}
|
||||||
|
}
|
12
ts/index.ts
12
ts/index.ts
@ -1,10 +1,15 @@
|
|||||||
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 { HrtMeasurement } from './early.hrtMeasurement'
|
||||||
|
|
||||||
|
export {
|
||||||
|
HrtMeasurement
|
||||||
|
}
|
||||||
|
|
||||||
let doText: boolean = false
|
let doText: boolean = false
|
||||||
let moduleName: string = 'undefined module name'
|
let moduleName: string = 'undefined module name'
|
||||||
let startTime = Date.now()
|
let startHrt: HrtMeasurement
|
||||||
|
|
||||||
if (process.argv.indexOf('-v') === -1) {
|
if (process.argv.indexOf('-v') === -1) {
|
||||||
doText = true
|
doText = true
|
||||||
@ -15,6 +20,8 @@ if (process.argv.indexOf('-v') === -1) {
|
|||||||
*/
|
*/
|
||||||
export let start = function (moduleNameArg: string = '', loaderLengthArg: string = '10') {
|
export let start = function (moduleNameArg: string = '', loaderLengthArg: string = '10') {
|
||||||
moduleName = moduleNameArg
|
moduleName = moduleNameArg
|
||||||
|
startHrt = new HrtMeasurement()
|
||||||
|
startHrt.start()
|
||||||
if (doText) {
|
if (doText) {
|
||||||
console.log(`**** starting ${beautycolor.coloredString(moduleNameArg, 'green')} ****`)
|
console.log(`**** starting ${beautycolor.coloredString(moduleNameArg, 'green')} ****`)
|
||||||
}
|
}
|
||||||
@ -22,8 +29,7 @@ export let start = function (moduleNameArg: string = '', loaderLengthArg: string
|
|||||||
|
|
||||||
export let stop = (): Promise<number> => {
|
export let stop = (): Promise<number> => {
|
||||||
let done = smartq.defer<number>()
|
let done = smartq.defer<number>()
|
||||||
let endTime = Date.now()
|
let earlyExecutionTime = startHrt.stop().milliSeconds
|
||||||
let earlyExecutionTime: number = (endTime - startTime)
|
|
||||||
let earlyExecutionTimeString: string = (earlyExecutionTime / 1000).toString()
|
let earlyExecutionTimeString: string = (earlyExecutionTime / 1000).toString()
|
||||||
console.log(`OK! -> finished loading within ${beautycolor.coloredString(earlyExecutionTimeString, 'blue')}`)
|
console.log(`OK! -> finished loading within ${beautycolor.coloredString(earlyExecutionTimeString, 'blue')}`)
|
||||||
done.resolve(earlyExecutionTime)
|
done.resolve(earlyExecutionTime)
|
||||||
|
Reference in New Issue
Block a user