advanced-python-homework-2023/interpreters/test.py
2023-10-06 13:14:14 +03:00

44 lines
1.1 KiB
Python

import time
import sys
from pure_with_types import mandelbrot_with_types
from pure_no_types import mandelbrot_no_types
from np_extended import mandelbrot_np
def test(function):
tic = time.perf_counter_ns()
image = function()
toc = time.perf_counter_ns()
return (toc - tic) / 1e9
def try_func(function):
try:
time = test(function)
except Exception as e:
raise e
return time
def main(arg):
interpreter = arg[1]
time_with_types = "err"
time_no_types = "err"
time_np = "err"
time_with_types = try_func(mandelbrot_with_types)
time_no_types = try_func(mandelbrot_no_types)
time_np = try_func(mandelbrot_np)
response = f"interpreter: {interpreter}\n"\
"time in seconds:\n"\
"with types\tno types\twith numpy\n"\
f"err\t{time_no_types:.6f}\t{time_np:.6f}"
# response = "{:.6f} {:.6f}".format(time_no_types, time_np)
print(response)
with open("results/{}.txt".format(interpreter), "w", encoding="utf8") as f:
f.write(response)
if __name__ == "__main__":
main(sys.argv)