Debug WIP: Added option for specifying cycles to run when measuring time

This commit is contained in:
Allan Jeremy 2022-06-06 17:01:55 +03:00
parent 74784f98af
commit a982368974

View file

@ -1,3 +1,4 @@
from itertools import cycle
import os, sys, time import os, sys, time
try: try:
import numpy as np import numpy as np
@ -8,22 +9,34 @@ except ModuleNotFoundError:
duration_list = [] duration_list = []
for i in range(1,10): DEFAULT_CYCLES_TO_RUN = 100
cycles_to_run = DEFAULT_CYCLES_TO_RUN
try:
cycles_to_run = sys.argv[3] if(sys.argv[3]) else DEFAULT_CYCLES_TO_RUN
cycles_to_run = int(cycles_to_run)
except IndexError:
pass
except (ValueError, TypeError):
cycles_to_run = DEFAULT_CYCLES_TO_RUN
print("Error: Cycles to run argument must be an integer. Using default value of {}".format(DEFAULT_CYCLES_TO_RUN))
# Numpy complains if we provide a cycle count of less than 3 ~ default to 3 whenever a lower value is provided
cycles_to_run = cycles_to_run if cycles_to_run > 2 else 3
for i in range(1,cycles_to_run):
start = time.perf_counter() start = time.perf_counter()
# Run the code you want to measure here
os.system(sys.argv[1]) os.system(sys.argv[1])
end = time.perf_counter() end = time.perf_counter()
duration_ms = (end - start) * 1000 duration_ms = (end - start) * 1000
print("SUCCESS: {} : {:.2f}ms +/- {:.2f}% on luau ".format('duration', duration_ms,0))
duration_list.append(duration_ms) duration_list.append(duration_ms)
# Stats # Stats
mean = np.mean(duration_list) mean = np.mean(duration_list)
std_err = stats.sem(duration_list) std_err = stats.sem(duration_list)
print("--------------------------------------------------------------------------------")
print("SUCCESS: {} : {:.2f}ms +/- {:.2f}% on luau ".format('duration', mean,std_err)) print("SUCCESS: {} : {:.2f}ms +/- {:.2f}% on luau ".format('duration', mean,std_err))