Last active
May 24, 2019 19:31
-
-
Save tytydraco/4e302433e0ba6537dee3a79ccbe14b49 to your computer and use it in GitHub Desktop.
Find the ideal HZ rate for the assumed data.
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 math | |
import decimal | |
### BEGIN USER TUNABLS ### | |
tolerance = 14 # max ms for scheduling | |
tasks = 8 # avg tasks occurring at any instance | |
cores = 8 # cores allowed to contain tasks | |
hz_min = 1 # min hz allowed | |
hz_max = 2000 # max hz allowed | |
inc = 1 # hz increment | |
exact = True # only show exact decimals (rational) | |
### END USER TUNABLS ### | |
cycles = math.ceil(tasks / cores) # number of cycles to schedule all tasks | |
# setup decimal api | |
if (exact): | |
ctx = decimal.Context(prec=6, Emax=999, clamp=1, traps=[decimal.Inexact]) | |
decimal.setcontext(ctx) | |
thousand = ctx.create_decimal(1000) | |
for hz in range(hz_min, hz_max + 1, inc): | |
# ensure exact values (if enabled) | |
if (exact): | |
try: | |
ms = cycles * thousand / ctx.create_decimal(str(hz)) | |
except decimal.Inexact: | |
continue | |
# otherwise don't worry about exactness | |
else: | |
ms = cycles * 1000 / hz | |
# ensure ms doesn't exceed specified tolerance | |
if (ms > tolerance): | |
continue | |
print("{}\thz\t-->\t{:0.4f}\tms".format(hz, ms)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment