now has hrtime Measurement
This commit is contained in:
23
ts/index.ts
23
ts/index.ts
@ -1,6 +1,7 @@
|
||||
import 'typings-global'
|
||||
import * as beautycolor from 'beautycolor'
|
||||
import * as smartq from 'smartq'
|
||||
import * as process from 'process'
|
||||
|
||||
let doText: boolean = false
|
||||
let moduleName: string = 'undefined module name'
|
||||
@ -29,3 +30,25 @@ export let stop = (): Promise<number> => {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user