Skip to content

Instantly share code, notes, and snippets.

@brccabral
Last active October 20, 2023 02:44
Show Gist options
  • Save brccabral/7d6dc5cdd9ca49bb723e13d40c572f38 to your computer and use it in GitHub Desktop.
Save brccabral/7d6dc5cdd9ca49bb723e13d40c572f38 to your computer and use it in GitHub Desktop.
Profile Python code with KCacheGrind

Profile Python code with KCacheGrind

import cProfile
import pstats
...
...
with cProfile.Profile() as pr:
    main()

stats = pstats.Stats(pr)
stats.sort_stats(pstats.SortKey.TIME)
stats.print_stats()
stats.dump_stats(filename="needs_profiling.prof")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment