Profile Your Code

I spent some time profiling an application at work today. I’m always surprised at what I find. The parts I expect to be slow often surprise me by how fast they are. Yet, other parts that I hadn’t considered as targets for optimization turn out to be the real dogs. The moral of the story is that the first step of optimizing an app should be profiling. You can often improve performance drastically by just going after the low hanging fruit.

The two major things I look for are methods that just take a damn long time and methods that are called an inexplicably large number of times. A method that completes in an average of, say, 10ms might seem like it’s not worth your efforts. If it’s called 1,000 times, it still owns 10 seconds of your total operation time. If you can get it to operate in 8ms, you save 2 seconds. Or, if you can get it to be called 500 times instead of 1,000, you save 5 seconds.

Leave a Reply