Program optimization

Program optimization—that is, taking a working, slow program and making it into a working, fast program—is an important part of any programmer’s skillset. However, it’s a bit tricky. For one thing, after a few easy tricks are used up, you’re typically getting speed by trading away something else, like readable code or portability to other architectures or operating systems, or programmers not having headaches. For another thing, ‘speeeeeeed’ can be a siren song that leads you to spend your time on optimizing things that aren’t even right yet, or are fast enough already.

As they say, ‘premature optimization is the root of all evil’.

With that word of warning, here are a couple of interesting articles about important ways your architecture affects your program’s performance.

Both these articles use code examples in C#, so they will require some translating if you want to try them out in C. Nonetheless, I encourage you to do so. A great way to see how a program is performing in terms of cache misses and branch mispredictions is to use callgrind, a tool built on the foundation of valgrind.

Finally, here is an interesting story of optimization in the wild.

You have attempted of activities on this page