-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c79634
commit 0df25ff
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
Created on 2022-11-18 | ||
@author: wf | ||
""" | ||
import time | ||
|
||
|
||
class Profiler: | ||
""" | ||
simple profiler | ||
""" | ||
|
||
def __init__(self, msg, profile=True, with_start: bool = True): | ||
""" | ||
construct me with the given msg and profile active flag | ||
Args: | ||
msg(str): the message to show if profiling is active | ||
profile(bool): True if messages should be shown | ||
""" | ||
self.msg = msg | ||
self.profile = profile | ||
if with_start: | ||
self.start() | ||
|
||
def start(self): | ||
""" | ||
start profiling | ||
""" | ||
self.starttime = time.time() | ||
if self.profile: | ||
print(f"Starting {self.msg} ...") | ||
|
||
def time(self, extraMsg=""): | ||
""" | ||
time the action and print if profile is active | ||
""" | ||
elapsed = time.time() - self.starttime | ||
if self.profile: | ||
print(f"{self.msg}{extraMsg} took {elapsed:5.1f} s") | ||
return elapsed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters