Created
May 13, 2024 08:45
-
-
Save jonathan-s/d8b4a0a1dff6de7dd0af57f2c1c005a1 to your computer and use it in GitHub Desktop.
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
from pathlib import Path | |
import cProfile | |
class Profile: | |
def __init__(self, path: Path): | |
self.profiler = None | |
self.path = path | |
def __enter__(self): | |
self.profiler = cProfile.Profile() | |
self.profiler.enable() | |
return self | |
def __exit__(self, *args, **kwargs): | |
self.profiler.dump_stats(self.path) | |
self.profiler = None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment