Skip to content

Commit

Permalink
fix: Use only the "data" event to catch the firstByte timing
Browse files Browse the repository at this point in the history
It is triggered before the "readable" event. Less code and more correct
measurement.
  • Loading branch information
prantlf committed Nov 4, 2017
1 parent 13ab821 commit f5bb930
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/nettime.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ function nettime (options) {
return new Promise((resolve, reject) => {
start = getTime(process.hrtime())
protocol.get(parameters, localResponse => {
let firstByte

response = localResponse
response.once('readable', () => {
timings.firstByte = getDuration()
})
.on('data', () => {
response.on('data', () => {
if (!firstByte) {
timings.firstByte = getDuration()
firstByte = true
}
})
.on('end', () => {
timings.contentTransfer = getDuration()
Expand Down

0 comments on commit f5bb930

Please sign in to comment.