Skip to main content
3 of 4
add built-in modules, add explanations of when to use each tool
Gareth Rees
  • 50.1k
  • 22
  • 41

#Python#

timeit — built-in module for timing the execution of small bits of Python code. Start here! Many performance problems can be tackled using timeit and a willingness to experiment.

profile — built-in module for function-based deterministic profiling. Use this when your code is organized into functions and you're not sure which one is taking all the time.

line_profiler — package for line-by-line profiling. Try this if your code is not organized into functions, or if you tried profile and there was no clear culprit function.

benchmark — framework for writing benchmarks: like unittest but for performance tests rather than functionality tests.

Mast Mod
  • 13.9k
  • 2
  • 37
  • 90