-
-
Save jamesmunns/12968ef8b53f7cea87a12d5f7d3b5677 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
DEVICES = 32 | |
WINDOW_US = 100 | |
FIXED_ROUND_DELAY_SEC = 0.003 | |
# Less than 8 is bad | |
WINDOWS = 8 | |
print(f"{DEVICES} devices, {WINDOW_US}us per window, {FIXED_ROUND_DELAY_SEC * 1000}ms delay each round") | |
print("Time Slots, Average Rounds Taken, Average time taken (ms)") | |
while WINDOWS <= 1024: | |
rounds_taken = [] | |
for x in range(4096): | |
registered = 0 | |
rounds = 0 | |
while registered < DEVICES: | |
rounds += 1 | |
slots = [] | |
collisions = [] | |
unique = [] | |
to_register = DEVICES - registered | |
for i in range(to_register): | |
slots.append(random.randrange(WINDOWS)) | |
# print(f"slots: {slots}") | |
for i in slots: | |
if i in collisions: | |
pass | |
elif i in unique: | |
collisions.append(i) | |
while i in unique: | |
unique.remove(i) | |
else: | |
unique.append(i) | |
registered += len(unique) | |
# print("Round ended.") | |
# print(f"Registered: {len(unique)}") | |
# print(f"Unique collisions: {len(collisions)}") | |
# print(f"remaining: {DEVICES - registered}") | |
# print(f"complete. Rounds: {rounds}") | |
rounds_taken.append(rounds) | |
avg_rounds = sum(rounds_taken)/len(rounds_taken) | |
print(f"{WINDOWS}, {avg_rounds:0.03f}, {(((WINDOW_US / 1000000) * avg_rounds) + (avg_rounds * FIXED_ROUND_DELAY_SEC)) * 1000:0.03f}") | |
WINDOWS *= 2 |
Author
jamesmunns
commented
Nov 4, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment