@@ -28,6 +28,7 @@ var http = require('http')
28
28
, Multipart = require ( './lib/multipart' ) . Multipart
29
29
, Redirect = require ( './lib/redirect' ) . Redirect
30
30
, Tunnel = require ( './lib/tunnel' ) . Tunnel
31
+ , now = require ( 'performance-now' )
31
32
32
33
var safeStringify = helpers . safeStringify
33
34
, isReadStream = helpers . isReadStream
@@ -36,7 +37,6 @@ var safeStringify = helpers.safeStringify
36
37
, copy = helpers . copy
37
38
, version = helpers . version
38
39
, globalCookieJar = cookies . jar ( )
39
- , hrTimeStart
40
40
41
41
42
42
var globalPool = { }
@@ -92,28 +92,6 @@ function responseToJSON() {
92
92
}
93
93
}
94
94
95
- function getHrTime ( ) {
96
- if ( typeof process === 'undefined' || ! process . hrtime ) {
97
- return 0
98
- }
99
-
100
- var hr = process . hrtime ( )
101
- // convert to nanoseconds
102
- return hr [ 0 ] * 1e9 + hr [ 1 ]
103
- }
104
-
105
- hrTimeStart = getHrTime ( )
106
-
107
- function getTimeFromStart ( ) {
108
- // in the browser, use performance.now()
109
- if ( typeof performance !== 'undefined' && performance . now ) {
110
- return performance . now ( )
111
- }
112
-
113
- // in nodejs, use process.hrtime() (converting back to milliseconds)
114
- return ( getHrTime ( ) - hrTimeStart ) / 1e6
115
- }
116
-
117
95
function Request ( options ) {
118
96
// if given the method property in options, set property explicitMethod to true
119
97
@@ -739,7 +717,7 @@ Request.prototype.start = function () {
739
717
var self = this
740
718
741
719
if ( self . timing ) {
742
- var startTime = getTimeFromStart ( )
720
+ var startTime = now ( )
743
721
}
744
722
745
723
if ( self . _aborted ) {
@@ -799,9 +777,9 @@ Request.prototype.start = function () {
799
777
} )
800
778
self . req . on ( 'socket' , function ( socket ) {
801
779
if ( self . timing ) {
802
- self . timings . socket = getTimeFromStart ( )
780
+ self . timings . socket = now ( )
803
781
socket . on ( 'connect' , function ( ) {
804
- self . timings . connect = getTimeFromStart ( )
782
+ self . timings . connect = now ( )
805
783
} )
806
784
}
807
785
@@ -888,13 +866,13 @@ Request.prototype.onRequestResponse = function (response) {
888
866
var self = this
889
867
890
868
if ( self . timing ) {
891
- self . timings . response = getTimeFromStart ( )
869
+ self . timings . response = now ( )
892
870
}
893
871
894
872
debug ( 'onRequestResponse' , self . uri . href , response . statusCode , response . headers )
895
873
response . on ( 'end' , function ( ) {
896
874
if ( self . timing ) {
897
- self . timings . end = getTimeFromStart ( )
875
+ self . timings . end = now ( )
898
876
899
877
self . timings . dns = self . timings . socket - self . timings . start
900
878
self . timings . tcp = self . timings . connect - self . timings . socket
0 commit comments