-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
New version with english comments #12762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 12 commits
927fc55
c54f7bb
7072b86
9b29626
6806a7a
48f8920
daac334
b0ada11
c58ef37
b374385
083c945
f8f7ed1
27cf621
3a3671c
76e1190
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Author : Bosolindo Edhiengene Roger | ||
# email : [email protected] | ||
|
||
# This module contains codes about algorithms complexity as to estimate the time | ||
# an algorithm will take to be run. | ||
# Why do we find it usable ? | ||
# Because, knowing this kind of information tells you if your code or solution is | ||
# efficient or not ; it helps you not to fall trying to run such a code. | ||
|
||
|
||
def calc(operations: dict) -> float: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What doctest for calc function are you talking about? |
||
""" | ||
calc(operation: dict) -> float: | ||
This function aims to calculate how long an algorithm take, | ||
knowing only primary operations | ||
:param operations: | ||
A dictionary where the values are tuples, consisting of the number of times | ||
an operation is performed and its execution time, and the key should, | ||
preferably, be the name of the operation for better clarity and usability. | ||
:return: the time needed for the execution of this algorithm | ||
#>>> operations1 = {"addition":(2, 0.1), "subtraction":(1, 0.2)} | ||
#>>> operations2 = {"addition":(2, 0.1), "subtraction":(1, 0.2, 1)} | ||
#>>> calc(operations1) | ||
#>>> 0.4 | ||
#>>> calc(operations2) | ||
#>>> 0 | ||
""" | ||
temps = 0 | ||
for couple in operations.values(): | ||
# Case you give a shorter or a longer tuple | ||
if len(couple) != 2: | ||
return 0 | ||
# Otherwise | ||
temps += couple[0] * couple[1] | ||
|
||
return temps | ||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
|
||
doctest.testmod() | ||
operations1 = {"addition": (2, 0.1), "subtraction": (1, 0.2)} | ||
operations2 = {"addition": (2, 0.1), "subtraction": (1, 0.2, 1)} | ||
print(calc(operations1)) | ||
print(calc(operations2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file
other/time_algo_exec.py
, please provide doctest for the functioncalc