Debugging and Profiling Tools

Prof. Brian D. Davison

Computer Science & Engineering, Lehigh University

Announcements

More Debugging Tools

lint -- a static code checker

Lint goes further than -Wall, but also complains about non-errors.

Splint -- Secure Programming Lint

System call tracers

Strace

truss

Code Styles

Optimizing Execution Speed

What do the experts say?

Optimizing Code

Code Profilers

gprof

Rules for writing fast code (aka optimization)

    More from the Slashdot discussion...
  1. Avoid doing what you don't have to do. Sounds obvious but I rarely see code that does the absolute minimum it needs to. Most of the code I've seen to date seems to precalculate too much stuff, read too much data from external storage, redraw too much stuff on screen etc...
  2. Do it later. There are thousands of situations where you can postpone the actual computations.
    • Most string class implementations already make good use of this rule by only copying their buffers only when the "copied" buffer changes.
  3. Apply minimum algorithmic complexity. If you can use a hashmap instead of a treemap use the hash version it's O(1) vs O(log n). Use quicksort for just about any kind of sorting you need to do.
  4. Cache your data. There are some enormous performance gains that can be realized with smart caching strategies.
  5. Optimize using your language constructs. User the register keyword, use language idioms that you know compile into faster code etc... Scratch this rule! If you're applying rules one to four you can forget about this one and still have fast AND readable code.