-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new measure_time capability in ./utils (#760)
* add new measure_time capability in ./utils and move items related to Andrej's runner to andrej-runner * add __init__ to make utils a package * typo * typo * resolve name clash
- Loading branch information
Showing
6 changed files
with
51 additions
and
30 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
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
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
Empty file.
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,24 @@ | ||
from time import perf_counter | ||
from typing import Optional | ||
|
||
class measure_time: | ||
def __init__( | ||
self, | ||
message: Optional[str] = 'Time: {time:.3f} seconds' | ||
): | ||
self.message = message | ||
|
||
def __enter__( | ||
self, | ||
): | ||
self.start = perf_counter() | ||
self.message | ||
return self | ||
|
||
def __exit__(self, type, value, traceback): | ||
self.time = perf_counter() - self.start | ||
if self.message is not None: | ||
print(self.message.format(time=self.time)) | ||
|
||
def get_time(self): | ||
return self.time |