Created
March 27, 2019 13:42
-
-
Save gombosg/6c781ed2cd77a317968a6b5c5687d022 to your computer and use it in GitHub Desktop.
Stress testing for Coursera's Algorithmic Toolbox course
This file contains hidden or 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
# file should export: | |
# functions = [f1, f2, ..., fn] functions to stress test (maybe the first will be the naive implementation) | |
# gen_params() - returns a list or tuple of function parameters to test the functions with | |
# in main file use if __name__=="__main__" for standard IO code so that you can submit it for grading | |
import sys | |
from time import time | |
import FILE as runner # import your filename here | |
def stress_test(): | |
print("Start") | |
n = 0 | |
fs = runner.functions | |
while True: | |
results = [] | |
times = [] | |
data = runner.gen_params() | |
for f in fs: | |
t0 = time() | |
results.append(f(*data)) | |
t1 = time() | |
times.append(t1 - t0) | |
if all(x == results[0] for x in results): | |
print("OK", n, "| Input:", data, "| Times/ratio:", *[[fs[l].__name__, f'{times[l]:.2f}', f'{times[l] / times[0]:.2f}'] for l in range(len(times))]) | |
n += 1 | |
else: | |
print("Wrong answer", results, "Data:", data) | |
break | |
stress_test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment