-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from yusufshakeel/dev
v0.8.6
- Loading branch information
Showing
8 changed files
with
184 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
const NS_PER_SEC = 1e9; | ||
|
||
function Performance() { | ||
let startedAt = 0; | ||
let duration = 0; | ||
|
||
this.startTimer = () => { | ||
startedAt = process.hrtime(); | ||
}; | ||
|
||
this.stopTimer = () => { | ||
duration = process.hrtime(startedAt); | ||
}; | ||
|
||
this.stats = () => { | ||
const nano = duration[0] * NS_PER_SEC + duration[1]; | ||
return { | ||
duration: { | ||
nano, | ||
micro: nano / 1e3, | ||
milli: nano / 1e6, | ||
second: nano / 1e9 | ||
} | ||
}; | ||
}; | ||
} | ||
|
||
module.exports = Performance; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
const Performance = require('../../app/performance.js'); | ||
|
||
test('Should be able to return stats', () => { | ||
const performance = new Performance(); | ||
performance.startTimer(); | ||
performance.stopTimer(); | ||
const result = performance.stats(); | ||
expect(Object.keys(result)).toStrictEqual(['duration']); | ||
expect(Object.keys(result.duration)).toStrictEqual(['nano', 'micro', 'milli', 'second']); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters