Skip to content

Instantly share code, notes, and snippets.

@jonathan-s
Created May 13, 2024 08:45
Show Gist options
  • Save jonathan-s/d8b4a0a1dff6de7dd0af57f2c1c005a1 to your computer and use it in GitHub Desktop.
Save jonathan-s/d8b4a0a1dff6de7dd0af57f2c1c005a1 to your computer and use it in GitHub Desktop.
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