Skip to content

Commit

Permalink
added profiling decorator and makefile updates
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronSaikovski committed Jul 28, 2023
1 parent fa0e0db commit 1131d29
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ clean:
test: activate
poetry run python -m pytest tests

## update - updates dependency versions
update: activate
poetry update -v

## lint - Lints the project using ruff --fix
lint: activate
poetry run ruff . --fix
Expand Down
27 changes: 26 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,30 @@
Longer description of this module.
"""
import utils.console_helper as console
import utils.logging_helper as logging
import utils.profiling_helper as profiler

# ******************************************************************************** #

@logging.log
@profiler.profile_func
def add_nums_test (num1: int, num2: int) -> int:
"""adds two numbers as a test
Args:
num1 (int): Value 1
num2 (int): Value 2_description_
Returns:
int: sum of numbers
"""
return num1 + num2


# ******************************************************************************** #

@profiler.profile_func
def main():
"""Example function with types documented in the docstring.
Expand All @@ -31,7 +52,11 @@ def main():
"""
print("** This is the main method.** ")

console.print_ok_message("** This is the main method.** ")

nums_test = add_nums_test(50,50)
print (f"Adding nums: {nums_test}")


# ******************************************************************************** #
Expand Down
27 changes: 27 additions & 0 deletions utils/profiling_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Profiling function helper - used to profile function performance
"""
import functools
import time

# ******************************************************************************** #

def profile_func (func) :
"""
Profile Logging decorator
"""
@functools.wraps(func)
def wrapper (*args, **kwargs):
start = time.time ()
func (*args, **kwargs)
end = time.time ()
print (f"Elapsed time: {(end - start) *1000:.3f}ms")
return wrapper

# ******************************************************************************** #

# usage of decorator to measure function performance
# @profile_func
# def add (num1: int, num2: int) :
# print (f"Add {num1} and {num2}")
# return num1 + num2

0 comments on commit 1131d29

Please sign in to comment.