Skip to content

Instantly share code, notes, and snippets.

@nitish6174
Last active February 22, 2021 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nitish6174/99944f00ef99f23ad3a08907728dae60 to your computer and use it in GitHub Desktop.
Save nitish6174/99944f00ef99f23ad3a08907728dae60 to your computer and use it in GitHub Desktop.

PyInstrument

from pyinstrument import Profiler
profiler = Profiler()

profiler.start()

# --- code to profile : start ---
# e.g. :-
# np.random.randint(1, 7, 1000)
# --- code to profile : end ---

profiler.stop()

# --- view profiling result ---
print(profiler.output_text(unicode=True, color=True, show_all=True))

cProfiler

import cProfile
import pstats

command_to_profile = '<cmd to run>'
dump_file = '</path/to/dump/file>'

cProfile.run(command_to_profile, dump_file)
p = pstats.Stats(dump_file)
p.sort_stats('cumulative').print_stats(50)

Python

  • pdb : The Python Debugger
  • cProfiler : Get profile for running time of various functions
  • KCacheGrind : Generate call graph of functions
  • valgrind : Profile memory usage by program
  • gperftools : Set of tools for performance profiling and memory checking. Generates a call graph output
  • pylint : Source code syntax & linting checker
  • pyreverse : Creates UML diagrams for python code. Included in pylint
  • pyflakes : Similar to pylint

C++, Python/C extension, Python C API

  • gdb
  • gprof
  • pprof
  • KCacheGrind
  • yep

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment