Skip to content

Commit 48f8920

Browse files
authored
Module to calulate algorithms' time execution
This add is about algorithms' complexity. The goal is to be able, for a given algorithm, knowing primary operations and their execution time, to predict how long it will take
1 parent 6806a7a commit 48f8920

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

other/time_algo_exec.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Auteur : Bosolindo Edhiengene Roger
2+
3+
4+
def calc(operations: dict) -> float:
5+
"""
6+
calc(operation: dict) -> float:
7+
Ce programme sert à calculer le temps d'éxecution des algorithmes en fonction
8+
des opérations primitives traitées
9+
:param operations: dictionnaire des couples (nombre de fois, temps d'exécution)
10+
avec comme clé, l'opération primitive(de préférence)
11+
:return: le temps d'exécution de l'algorithme si le format de "operations" est bon,
12+
0 sinon
13+
14+
#>>> operations1 = {"addition":(2, 0.1), "subtraction":(1, 0.2)}
15+
#>>> operations2 = {"addition":(2, 0.1), "subtraction":(1, 0.2, 1)}
16+
#>>> calc(operations1)
17+
#>>> 0.4
18+
#>>> calc(operations2)
19+
#>>> 0
20+
"""
21+
temps = 0
22+
for couple in operations.values():
23+
if len(couple) != 2:
24+
return 0
25+
temps += couple[0] * couple[1]
26+
27+
return temps
28+
29+
30+
if __name__ == "__main__":
31+
import doctest
32+
33+
doctest.testmod()
34+
operations1 = {"addition": (2, 0.1), "subtraction": (1, 0.2)}
35+
operations2 = {"addition": (2, 0.1), "subtraction": (1, 0.2, 1)}
36+
print(calc(operations1))
37+
print(calc(operations2))

0 commit comments

Comments
 (0)