Added a perf procedure to support download & upload on one stream

This commit is contained in:
Ludovic Chenut 2023-07-06 11:50:43 +02:00
parent 2ea83c609a
commit 066ed8d3b1
No known key found for this signature in database
GPG Key ID: D9A59B1907F1D50C

View File

@ -106,8 +106,36 @@ proc perfUpload*(p: Perf, conn: Connection,
await conn.write(buf[0..<toWrite])
size -= toWrite
await conn.close()
await conn.join()
let duration = Moment.now() - start
trace "got upload benchmark duration", conn, duration
return duration
proc perf*(p: Perf, conn: Connection,
sizeToWrite: uint64 = 0, sizeToRead: uint64 = 0):
Future[Duration] {.async, public.} =
var
size = sizeToWrite
buf: array[PerfSize, byte]
let start = Moment.now()
trace "starting perfomance benchmark", conn
await conn.write(toSeq(toBytesBE(sizeToRead)))
while size > 0:
let toWrite = min(size, PerfSize)
await conn.write(buf[0..<toWrite])
size -= toWrite
await conn.close()
size = sizeToRead
while size > 0:
let toRead = min(size, PerfSize)
await conn.readExactly(addr buf[0], toRead.int)
size = size - toRead
let duration = Moment.now() - start
return duration