forked from sabkaryan/python-core-homework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
37 lines (29 loc) · 1.11 KB
/
__init__.py
File metadata and controls
37 lines (29 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import functools
from ex2 import fetcher
import time
CALL_COUNT = 10
def benchmark(num):
"""
Совершает num прогонов переданной функции и выводит в консоль время каждого прогона и среднее время всех прогонов
:param num: число итераций
:return: функцию обёртку
"""
def wrapper(func):
@functools.wraps(func)
def inner(*args, **kwargs):
total_time = 0
counter = 0
while counter != num:
start_time = time.time()
func(*args, **kwargs)
end_time = time.time()
spent_time = end_time - start_time
total_time += spent_time
counter += 1
print(f'Прогон {counter} время выполнения прогона: {spent_time}')
print(f'Среднее время всех прогонов: {total_time / num}')
return inner
return wrapper
@benchmark(CALL_COUNT)
def fetch_page(url):
fetcher.get(url)