mirror of
https://github.com/vacp2p/nim-libp2p-experimental.git
synced 2025-01-27 10:35:10 +00:00
Added a perf procedure to support download & upload on one stream
This commit is contained in:
parent
2ea83c609a
commit
066ed8d3b1
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user