ChuanyuXue / udp-latency

A single Python file network latency testing tool by UDP.
MIT License
33 stars 9 forks source link

divide by zero on Windows #5

Closed ChuanyuXue closed 3 months ago

ChuanyuXue commented 4 months ago

When I run it on a single Windows computer, I get a divide by zero with the default options:

C:\Users\Devin\Downloads>C:\Python310\python.exe udp_latency.py -c | ---------- Sychonizing Server & Client by PTP ------------ | | Client: 20002 | Packet: 1 | Time: 1716832507661762600 | Data size: 1468 | Traceback (most recent call last): File "C:\Users\Devin\Downloads\udp_latency.py", line 269, in client.send( File "C:\Users\Devin\Downloads\udp_latency.py", line 102, in send

I can run it fine by using --dyna False on the client side.

When I run it on my computer, the current_time and start_time are the same, which results in a divide by zero: frequency: 1.0 current_time: 1716832724571958100 start_time: 1716832724571958100 current_time - start_time: 0

I suspect that this is only an issue on Windows and is because of the following: https://stackoverflow.com/a/1938096

I wonder what the best approach is to prevent the divide by zero, would something like the following work or would this skew the results? if (current_time == start_time): current_time = start_time + 1 # prevent divide by zero if using dyna on Windows due to +/- 16 ms accuracy (https://stackoverflow.com/a/1938096)

Would it be better to run without dyna?

ChuanyuXue commented 3 months ago

7bbfcae3b46aeabc4f9f18215248a4739f86ca4e