/
ilya.petrash
/
SimplePyScripts
Обзор
Документация
Войти
/
ilya.petrash
/
SimplePyScripts
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
time_this_using_with.py
41 строка
816 B
gil9red
Refactoring. Using f-strings
26 июн 2023, 12:49
26 июн 2023, 12:49
e7326ee
Код
Авторство
О чём код?
#!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = "ipetrash" from timeit import default_timer class TimeThis: def __init__(self, title="TimeThis"): self.title = title self.start_time = None def __enter__(self): self.start_time = default_timer() return self def __exit__(self, exc_type, exc_value, exc_traceback): print( f"[{self.title}] total time: {default_timer() - self.start_time} sec" ) if __name__ == "__main__": import time with TimeThis(): time.sleep(1) with TimeThis("Test"): text = "" for i in range(10**6): text += str(i) with TimeThis("Test"): items = [] for i in range(10**6): items.append(str(i)) text = "".join(items)