Skip to content

Commit

Permalink
🎨 feat(tools): implement timeing decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
InnoFang committed Nov 10, 2023
1 parent 94bad17 commit cebac09
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions code_counter/tools/timing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import time


def timing_decorator(func):
"""
Decorator to measure the execution time of a function.
Parameters
----------
func : callable
The function to be measured.
Returns
-------
callable
The decorated function.
"""

def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
elapsed_time = end_time - start_time
print(f"The '{func.__name__}' operation took a total of {elapsed_time:.5f} seconds.")
return result

return wrapper

0 comments on commit cebac09

Please sign in to comment.