Commit 305b81db authored by Martin Sustrik's avatar Martin Sustrik

higher precision time measurement in python perf tests

parent 4d07d7ca
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
# #
import sys import sys
from datetime import datetime import time
import libpyzmq import libpyzmq
def main (): def main ():
...@@ -41,15 +41,15 @@ def main (): ...@@ -41,15 +41,15 @@ def main ():
msg = s.recv () msg = s.recv ()
assert len (msg) == message_size assert len (msg) == message_size
start = datetime.now () start = time.clock ()
for i in range (1, message_count): for i in range (1, message_count):
msg = s.recv () msg = s.recv ()
assert len (msg) == message_size assert len (msg) == message_size
end = datetime.now() end = time.clock ()
elapsed = (end - start).seconds * 1000000 + (end - start).microseconds elapsed = (end - start) * 1000000
if elapsed == 0: if elapsed == 0:
elapsed = 1 elapsed = 1
throughput = (1000000.0 * float (message_count)) / float (elapsed) throughput = (1000000.0 * float (message_count)) / float (elapsed)
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
# #
import sys import sys
from datetime import datetime import time
import libpyzmq import libpyzmq
def main (): def main ():
...@@ -40,16 +40,17 @@ def main (): ...@@ -40,16 +40,17 @@ def main ():
msg = ''.join ([' ' for n in range (0, message_size)]) msg = ''.join ([' ' for n in range (0, message_size)])
start = datetime.now () start = time.clock ()
for i in range (0, roundtrip_count): for i in range (0, roundtrip_count):
s.send (msg) s.send (msg)
msg = s.recv () msg = s.recv ()
assert len (msg) == message_size assert len (msg) == message_size
end = datetime.now () end = time.clock ()
delta = (end - start).microseconds + 1000000 * (end - start).seconds
latency = float (delta) / roundtrip_count / 2 elapsed = (end - start) * 1000000
latency = elapsed / roundtrip_count / 2
print "message size: %.0f [B]" % (message_size, ) print "message size: %.0f [B]" % (message_size, )
print "roundtrip count: %.0f" % (roundtrip_count, ) print "roundtrip count: %.0f" % (roundtrip_count, )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment