inflab4/extra3.py
2023-07-21 01:08:19 +03:00

46 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from timeit import default_timer as timer
import extra1
import extra2
import main_task
iterations = 10
def time_main() -> float:
start = timer()
file = open('schedule.xml', encoding='utf8')
contents = file.read()
xml_parser = main_task.XmlParser()
for i in range(iterations):
xml_parser.parse_xml(contents)
xml_parser.load_json()
end = timer()
return end - start
def time_extra1() -> float:
start = timer()
file = open('schedule.xml', encoding='utf8')
content = file.read()
for i in range(iterations):
extra1.xml_to_json(content, True)
end = timer()
return end - start
def time_extra2() -> float:
start = timer()
file = open('schedule.xml', encoding='utf8')
contents = file.read()
for i in range(iterations):
extra2.xml_to_json(contents)
end = timer()
return end - start
if __name__ == "__main__":
print(f'Количество итераций: {iterations}')
print(f'Основное задание (без regex и библиотек): {time_main():.4f} секунд')
print(f'Доп. задание №1 (с помощью библиотек xmltodict и json): {time_extra1():.4f} секунд')
print(f'Доп. задание №2 (с помощью regex): {time_extra2():.4f} секунд')