Skip to content

Commit f8f7ed1

Browse files
authored
Update time_algo_exec.py
1 parent 083c945 commit f8f7ed1

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

other/time_algo_exec.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33

44
# This module contains codes about algorithms complexity as to estimate the time
55
# an algorithm will take to be run.
6-
# Why do we find it usable ? Because, knowing this kind of information tells you if your code
7-
# or solution is efficient or not ; it helps you not to fall trying to run such a code.
6+
# Why do we find it usable ?
7+
# Because, knowing this kind of information tells you if your code or solution is
8+
# efficient or not ; it helps you not to fall trying to run such a code.
89

910

1011
def calc(operations: dict) -> float:
1112
"""
1213
calc(operation: dict) -> float:
13-
This function aims to calculate how long an algorithm take, knowing only primary operations
14-
:param operations: A dictionary where the values are tuples, consisting of the number of times
15-
an operation is performed and its execution time, and the key should
16-
preferably be the name of the operation for better clarity and usability.
17-
:return: the time needed for the execution of this algorithm(if format is okey for "operations") or 0
14+
This function aims to calculate how long an algorithm take,
15+
knowing only primary operations
16+
:param operations:
17+
A dictionary where the values are tuples, consisting of the number of times
18+
an operation is performed and its execution time, and the key should,
19+
preferably, be the name of the operation for better clarity and usability.
20+
:return: the time needed for the execution of this algorithm
1821
#>>> operations1 = {"addition":(2, 0.1), "subtraction":(1, 0.2)}
1922
#>>> operations2 = {"addition":(2, 0.1), "subtraction":(1, 0.2, 1)}
2023
#>>> calc(operations1)
@@ -24,8 +27,10 @@ def calc(operations: dict) -> float:
2427
"""
2528
temps = 0
2629
for couple in operations.values():
30+
# Case you give a shorter or a longer tuple
2731
if len(couple) != 2:
2832
return 0
33+
# Otherwise
2934
temps += couple[0] * couple[1]
3035

3136
return temps

0 commit comments

Comments
 (0)