From abede1e72a2adca1dfcd0c012ac51a956ab560d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= Date: Fri, 24 Jan 2020 00:19:06 -0500 Subject: [PATCH] pingpong: print execution time --- python/tools/pingpong.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/python/tools/pingpong.py b/python/tools/pingpong.py index 71bd9f31..14c90329 100755 --- a/python/tools/pingpong.py +++ b/python/tools/pingpong.py @@ -35,13 +35,21 @@ pong_node.ping(ping_node.getBound()) loc_ping = dht.InfoHash.get("toto99") loc_pong = dht.InfoHash.get(str(loc_ping)) +net = [] +for i in range(1,10): + node = dht.DhtRunner() + node.run(config=config) + node.ping(ping_node.getBound()) + net.append(node) + i = 0 MAX = 2048 loop = asyncio.get_event_loop() def done(h, ok): - print(h, "over", ok) + pass + #print(h, "over", ok) def ping(node, h): global i @@ -52,13 +60,20 @@ def ping(node, h): loop.stop() 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) loop.run_forever() + +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")