@@ -97,16 +97,23 @@ export class Perf implements Startable, PerfInterface {
97
97
const writeBlockSize = this . writeBlockSize
98
98
99
99
const initialStartTime = Date . now ( )
100
+ let lastReportedTime = Date . now ( )
100
101
const connection = await this . components . connectionManager . openConnection ( ma , {
101
102
...options ,
102
103
force : options . reuseExistingConnection !== true
103
104
} )
104
105
106
+ this . log ( 'opened connection after %d ms' , Date . now ( ) - lastReportedTime )
107
+ lastReportedTime = Date . now ( )
108
+
105
109
const stream = await connection . newStream ( this . protocol , options )
106
110
111
+ this . log ( 'opened stream after %d ms' , Date . now ( ) - lastReportedTime )
112
+ lastReportedTime = Date . now ( )
113
+
107
114
let lastAmountOfBytesSent = 0
108
- let lastReportedTime = Date . now ( )
109
115
let totalBytesSent = 0
116
+ const uploadStart = Date . now ( )
110
117
111
118
// tell the remote how many bytes we will send. Up cast to 64 bit number
112
119
// as if we send as ui32 we limit total transfer size to 4GB
@@ -160,71 +167,14 @@ export class Perf implements Startable, PerfInterface {
160
167
161
168
yield * output
162
169
163
- /*
164
- const b = byteStream(stream)
165
- await b.write(uint8Buf.subarray(0, 8), options)
166
-
167
- while (sendBytes > 0) {
168
- let toSend: number = writeBlockSize
169
-
170
- if (toSend > sendBytes) {
171
- toSend = sendBytes
172
- }
173
-
174
- const chunk = uint8Buf.subarray(0, toSend)
175
-
176
- await b.write(chunk, options)
177
-
178
- sendBytes -= toSend
179
-
180
- if (Date.now() - lastReportedTime > 1000) {
181
- yield {
182
- type: 'intermediary',
183
- timeSeconds: (Date.now() - lastReportedTime) / 1000,
184
- uploadBytes: lastAmountOfBytesSent,
185
- downloadBytes: 0
186
- }
187
-
188
- // record last reported time after `console.log` because it can
189
- // affect benchmark timings
190
- lastReportedTime = Date.now()
191
- lastAmountOfBytesSent = 0
192
- }
193
-
194
- lastAmountOfBytesSent += toSend
195
- totalBytesSent += toSend
196
- }
197
-
198
- // sent all the bytes, close the write end of the stream
199
- await b.unwrap().closeWrite()
170
+ this . log ( 'upload complete after %d ms' , Date . now ( ) - uploadStart )
200
171
201
- */
202
172
// Read the received bytes
203
173
let lastAmountOfBytesReceived = 0
204
174
lastReportedTime = Date . now ( )
205
175
let totalBytesReceived = 0
206
- /*
207
- while (totalBytesReceived < receiveBytes) {
208
- const buf = await b.read(1024, options)
209
-
210
- if (Date.now() - lastReportedTime > 1000) {
211
- yield {
212
- type: 'intermediary',
213
- timeSeconds: (Date.now() - lastReportedTime) / 1000,
214
- uploadBytes: 0,
215
- downloadBytes: lastAmountOfBytesReceived
216
- }
176
+ const downloadStart = Date . now ( )
217
177
218
- // record last reported time after `console.log` because it can
219
- // affect benchmark timings
220
- lastReportedTime = Date.now()
221
- lastAmountOfBytesReceived = 0
222
- }
223
-
224
- lastAmountOfBytesReceived += buf.byteLength
225
- totalBytesReceived += buf.byteLength
226
- }
227
- */
228
178
for await ( const buf of stream . source ) {
229
179
if ( Date . now ( ) - lastReportedTime > 1000 ) {
230
180
yield {
@@ -244,6 +194,8 @@ export class Perf implements Startable, PerfInterface {
244
194
totalBytesReceived += buf . byteLength
245
195
}
246
196
197
+ this . log ( 'download complete after %d ms' , Date . now ( ) - downloadStart )
198
+
247
199
if ( totalBytesReceived !== receiveBytes ) {
248
200
throw new Error ( `Expected to receive ${ receiveBytes } bytes, but received ${ totalBytesReceived } ` )
249
201
}
0 commit comments