75 lines
2.4 KiB
Python
75 lines
2.4 KiB
Python
import os
|
|
import sys
|
|
import time
|
|
from glob import glob
|
|
from pathlib import Path
|
|
from subprocess import PIPE, STDOUT, run
|
|
|
|
from pytablewriter import MarkdownTableWriter
|
|
from pytablewriter.style import Style
|
|
|
|
|
|
def read_md():
|
|
"""
|
|
Read README.md
|
|
"""
|
|
with open("../README.md", "r") as f:
|
|
md = [line.strip() for line in f.readlines() if line.strip() != ""][1:]
|
|
return md
|
|
|
|
def write_md(results):
|
|
"""
|
|
Write to README.md
|
|
"""
|
|
with open("../dummy.md", "w") as f:
|
|
f.write(results)
|
|
|
|
def execute():
|
|
"""
|
|
Execute script and return output
|
|
"""
|
|
def _file_stem(f):
|
|
return f[-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 = [], []
|
|
julia_problem_numbers, julia_timings, julia_results = [], [], []
|
|
for script in scripts[:5]:
|
|
# _res = run(["python3", 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_timings.append(_res[1].split("(")[0])
|
|
julia_results.append(_res[3])
|
|
|
|
writer = MarkdownTableWriter(
|
|
table_name="Project Euler Solutions",
|
|
# headers=["Problem #", "Result", "Execution time (Python)"],
|
|
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[-2:-1]):03d}", int(r[23:]), t] for p,t,r in zip(julia_problem_numbers, julia_timings, julia_results)],
|
|
column_styles=[
|
|
Style(align="center"),
|
|
Style(align="right", thousand_separator="_"),
|
|
Style(align="right"),
|
|
], # specify styles for each column
|
|
margin=1 # add a whitespace for both sides of each cell
|
|
)
|
|
writer.write_table()
|
|
return writer.dumps()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
md = read_md()
|
|
# print(md)
|
|
res = execute()
|
|
# print(res)
|
|
# write_md(res)
|