@@ -97,16 +97,23 @@ export class Perf implements Startable, PerfInterface {
9797 const writeBlockSize = this . writeBlockSize
9898
9999 const initialStartTime = Date . now ( )
100+ let lastReportedTime = Date . now ( )
100101 const connection = await this . components . connectionManager . openConnection ( ma , {
101102 ...options ,
102103 force : options . reuseExistingConnection !== true
103104 } )
104105
106+ this . log ( 'opened connection after %d ms' , Date . now ( ) - lastReportedTime )
107+ lastReportedTime = Date . now ( )
108+
105109 const stream = await connection . newStream ( this . protocol , options )
106110
111+ this . log ( 'opened stream after %d ms' , Date . now ( ) - lastReportedTime )
112+ lastReportedTime = Date . now ( )
113+
107114 let lastAmountOfBytesSent = 0
108- let lastReportedTime = Date . now ( )
109115 let totalBytesSent = 0
116+ const uploadStart = Date . now ( )
110117
111118 // tell the remote how many bytes we will send. Up cast to 64 bit number
112119 // as if we send as ui32 we limit total transfer size to 4GB
@@ -160,71 +167,14 @@ export class Perf implements Startable, PerfInterface {
160167
161168 yield * output
162169
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 )
200171
201- */
202172 // Read the received bytes
203173 let lastAmountOfBytesReceived = 0
204174 lastReportedTime = Date . now ( )
205175 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 ( )
217177
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- */
228178 for await ( const buf of stream . source ) {
229179 if ( Date . now ( ) - lastReportedTime > 1000 ) {
230180 yield {
@@ -244,6 +194,8 @@ export class Perf implements Startable, PerfInterface {
244194 totalBytesReceived += buf . byteLength
245195 }
246196
197+ this . log ( 'download complete after %d ms' , Date . now ( ) - downloadStart )
198+
247199 if ( totalBytesReceived !== receiveBytes ) {
248200 throw new Error ( `Expected to receive ${ receiveBytes } bytes, but received ${ totalBytesReceived } ` )
249201 }
0 commit comments