feat(tools): 新增题目时自动生成带计时装饰器的模板文件
This commit is contained in:
20
main.py
20
main.py
@@ -15,7 +15,25 @@ def add_newproblem(num: int, name: str | None = None) -> None:
|
||||
else:
|
||||
title = f"{num:04d}"
|
||||
Path(f"solutions/{title}").mkdir(parents=True, exist_ok=True)
|
||||
Path(f"solutions/{title}/euler_{num}.py").touch()
|
||||
file_name = f"solutions/{title}/euler_{num}.py"
|
||||
Path(file_name).touch()
|
||||
with open(file_name, "w") as f:
|
||||
f.write("""'''
|
||||
|
||||
'''
|
||||
import time
|
||||
|
||||
|
||||
def timer(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
start_time = time.time()
|
||||
result = func(*args, **kwargs)
|
||||
end_time = time.time()
|
||||
elapsed_time = end_time - start_time
|
||||
print(f"{func.__name__} time: {elapsed_time:.6f} seconds")
|
||||
return result
|
||||
return wrapper
|
||||
""")
|
||||
|
||||
|
||||
@app.command("list", help="List all problems in the projecteuler repository.")
|
||||
|
||||
Reference in New Issue
Block a user