Skip to content
Browse files

pingpong: print execution time

  • Loading branch information
aberaud committed Jan 24, 2020
1 parent 859d8dc commit abede1e72a2adca1dfcd0c012ac51a956ab560d8
Showing with 17 additions and 2 deletions.
  1. +17 −2 python/tools/
@@ -35,13 +35,21 @@
loc_ping = dht.InfoHash.get("toto99")
loc_pong = dht.InfoHash.get(str(loc_ping))

net = []
for i in range(1,10):
node = dht.DhtRunner()

i = 0
MAX = 2048

loop = asyncio.get_event_loop()

def done(h, ok):
print(h, "over", ok)
#print(h, "over", ok)

def ping(node, h):
global i
@@ -52,13 +60,20 @@ def ping(node, h):

def pong(node, h):
print(node.getNodeId().decode(), "got ping", h, i)
#print(node.getNodeId().decode(), "got ping", h, i)
loop.call_soon_threadsafe(ping, node, h)
return True

t1 = time.time()

ping_node.listen(loc_ping, lambda v, e: pong(pong_node, loc_pong) if not e else True)
pong_node.listen(loc_pong, lambda v, e: pong(ping_node, loc_ping) if not e else True)

ping(pong_node, loc_ping)


t2 = time.time()

print(MAX, "ping-pong done, took", t2 - t1, "s")
print(1000 * (t2 - t1)/MAX, "ms per rt", MAX/(t2 - t1), "rt per s")

0 comments on commit abede1e

Please sign in to comment.
You can’t perform that action at this time.