Refactoring
This commit is contained in:
parent
bec0385c36
commit
2225ae6b40
@ -24,27 +24,28 @@ def write_md(results):
|
|||||||
with open("../dummy.md", "w") as f:
|
with open("../dummy.md", "w") as f:
|
||||||
f.write(results)
|
f.write(results)
|
||||||
|
|
||||||
|
def _file_stem(f):
|
||||||
|
return f[-5:]
|
||||||
|
|
||||||
|
def get_problems(path=None, ext=None):
|
||||||
|
os.chdir(Path(path))
|
||||||
|
return sorted([script.as_posix() for script in Path(".").rglob(f"*[0-9].{ext}")], key=_file_stem)
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
"""
|
"""
|
||||||
Execute script and return output
|
Execute script and return output
|
||||||
"""
|
"""
|
||||||
def _file_stem(f):
|
# scripts = get_problems(path="Python", ext="py")
|
||||||
return f[-5:]
|
scripts = get_problems(path="Julia", ext="jl")
|
||||||
|
# print(scripts[:5])
|
||||||
# os.chdir(Path("Python/"))
|
|
||||||
os.chdir(Path("Julia/"))
|
|
||||||
# scripts = sorted([script.as_posix() for script in Path(".").rglob("*[0-9].py")], key=_file_stem)
|
|
||||||
scripts = sorted([script.as_posix() for script in Path(".").rglob("*[0-9].jl")], key=_file_stem)
|
|
||||||
# print(scripts)
|
|
||||||
|
|
||||||
python_timings, python_results = [], []
|
python_timings, python_results = [], []
|
||||||
julia_problem_numbers, julia_timings, julia_results = [], [], []
|
julia_problem_numbers, julia_timings, julia_results = [], [], []
|
||||||
for script in scripts[:5]:
|
for script in scripts[:5]:
|
||||||
# _res = run(["python3", f"{script}"], capture_output=True, text=True).stdout.split("\n")
|
# _res = run(["python3", f"{script}"], capture_output=True, text=True).stdout.split("\n")
|
||||||
|
# python_timings.append(_res[0])
|
||||||
|
# python_results.append(_res[2])
|
||||||
_res = run(["julia", f"{script}"], capture_output=True, text=True).stdout.split("\n")
|
_res = run(["julia", f"{script}"], capture_output=True, text=True).stdout.split("\n")
|
||||||
# print(_res)
|
|
||||||
# python_timings.append(_res[0])
|
|
||||||
# python_results.append(_res[2])
|
|
||||||
julia_problem_numbers.append(_res[0])
|
julia_problem_numbers.append(_res[0])
|
||||||
julia_timings.append(_res[1].split("(")[0])
|
julia_timings.append(_res[1].split("(")[0])
|
||||||
julia_results.append(_res[3])
|
julia_results.append(_res[3])
|
||||||
@ -52,9 +53,9 @@ def execute():
|
|||||||
writer = MarkdownTableWriter(
|
writer = MarkdownTableWriter(
|
||||||
table_name="Project Euler Solutions",
|
table_name="Project Euler Solutions",
|
||||||
# headers=["Problem #", "Result", "Execution time (Python)"],
|
# headers=["Problem #", "Result", "Execution time (Python)"],
|
||||||
|
# value_matrix=[[f"{int(t[25:28]):03d}", int(r[22:]), t[29:]] for t,r in zip(python_timings, python_results)],
|
||||||
headers=["Problem #", "Result", "Execution time (Julia)"],
|
headers=["Problem #", "Result", "Execution time (Julia)"],
|
||||||
# value_matrix=[[f"{int(t[26:28]):003d}", int(r[23:]), t[29:]] for t,r in zip(python_timings, python_results)],
|
value_matrix=[[f"{int(p[-5:-1]):03d}", int(r[23:]), t] for p,t,r in zip(julia_problem_numbers, julia_timings, julia_results)],
|
||||||
value_matrix=[[f"{int(p[-2:-1]):03d}", int(r[23:]), t] for p,t,r in zip(julia_problem_numbers, julia_timings, julia_results)],
|
|
||||||
column_styles=[
|
column_styles=[
|
||||||
Style(align="center"),
|
Style(align="center"),
|
||||||
Style(align="right", thousand_separator="_"),
|
Style(align="right", thousand_separator="_"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user