now has better hrtMeasurement

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

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