early/dist/index.js

54 lines
3.8 KiB
JavaScript
Raw Normal View History

2016-05-20 17:06:25 +00:00
"use strict";
2017-03-26 20:01:33 +00:00
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global");
2017-02-17 17:56:58 +00:00
const beautycolor = require("beautycolor");
const smartq = require("smartq");
2017-04-23 16:46:13 +00:00
const process = require("process");
2016-08-20 05:03:49 +00:00
let doText = false;
2016-09-15 12:45:58 +00:00
let moduleName = 'undefined module name';
2016-09-18 22:34:38 +00:00
let startTime = Date.now();
if (process.argv.indexOf('-v') === -1) {
2016-06-10 03:36:06 +00:00
doText = true;
}
2016-09-18 22:34:38 +00:00
/**
* start the loading
*/
2016-09-15 12:45:58 +00:00
exports.start = function (moduleNameArg = '', loaderLengthArg = '10') {
2016-08-20 05:03:49 +00:00
moduleName = moduleNameArg;
2016-09-18 22:34:38 +00:00
if (doText) {
2017-02-17 17:56:58 +00:00
console.log(`**** starting ${beautycolor.coloredString(moduleNameArg, 'green')} ****`);
2016-06-10 03:36:06 +00:00
}
2016-05-20 17:06:25 +00:00
};
2016-09-15 12:45:58 +00:00
exports.stop = () => {
2017-02-17 17:56:58 +00:00
let done = smartq.defer();
let endTime = Date.now();
let earlyExecutionTime = (endTime - startTime);
let earlyExecutionTimeString = (earlyExecutionTime / 1000).toString();
2017-03-26 20:01:33 +00:00
console.log(`OK! -> finished loading within ${beautycolor.coloredString(earlyExecutionTimeString, 'blue')}`);
2016-09-18 22:34:38 +00:00
done.resolve(earlyExecutionTime);
2016-06-11 21:53:48 +00:00
return done.promise;
2016-05-20 17:06:25 +00:00
};
2017-04-23 16:46:13 +00:00
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: nanoSe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