Day 16: Measure Performance Before Optimizing

Writing programs takes time, but writing correct and fast programs is even more difficult. That is why there is so much badly written software in the market. Bugs are the result of sloppy and rushed code. Programs are frequently slower than they need to be as a result.

In this situation, it sometimes seems smart to design systems that are efficient. But for many programmers, efficiency becomes an end in itself, and they end up trying to optimize code before understanding the real implications of these optimizations.

One of the most common problems is not understanding the real bottlenecks in the system. For example, when writing software for the web using standard architectures, accessing the data base is frequently the bottleneck of the system. When faced with this situation, it doesn’t matter if the code to handle string comparison is written in assembly or in Ruby, the result will be approximately the same.

Measuring Speed Up

There is an interesting result studied in computer architechture called the Ahmdal Law. This principle says that any optimization (say, getting twice the performance) applied to a part of the system that is responsible for only a small percentage of the execution time will result in a very small improvement.

For example, suppose that you improve the string handling code to be 10 times more efficient. This might give you hopes that the whole system will be a few times more efficient that it is. However, after measuring the system, you verify that the time spent on string comparison is 10% of the total time.

The result is that an operation that takes 10% of the total time now takes only 1% of the time. However, this means that the performance improvement for the whole system is just 9%.

If 9% still seems good for you, notice that I was very generous here. It is really hard to change something to be 10 times faster, unless you come up with a different algorithm. Also, the differences in percentage of usage are not commonly in the range 10 to 90%, but more frequently it is 1 to 99%. That is, most areas of your code contribute 1% or less to the running time, while bottlenecks such as network and database delays are responsible for 99% of the time.

Even for processor bound tasks this situation remains. There is probably a few small parts of your code that are responsible for 99% of the time spent in the program.

That is why measuring a system is so important. If you don’t know what is responsible for that figure of 99%, your efforts to improve the performance of the system are basicaly wasted. You should aim first at understanding what contributes to the bottlenecks in the system. Then, you can start planning on how to improve that area.

Further Reading

Read Computer Architecture: A Quantitative Approach to find everything you may want to know about Amdahl Law and how it applies to computer systems.

Similar Posts:

Similar Posts

1,038 Comments

  1. Oh my goodness! Incredible article dude! Thank you,
    However I am having issues with your RSS. I don’t understand the reason why I can’t subscribe to
    it. Is there anybody getting similar RSS issues? Anyone that knows the solution can you kindly
    respond? Thanks!!

  2. I was recommended this web site by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my difficulty.
    You’re amazing! Thanks!

  3. Amazing! This blog looks exactly like my old one! It’s on a totally different topic but it has pretty much
    the same layout and design. Excellent choice of colors!

  4. Thanks for another excellent post. The place else may anybody get that type of info in such an ideal means of writing?
    I have a presentation next week, and I am at the look for
    such information.

  5. Have you ever considered writing an ebook or guest authoring on other websites?

    I have a blog centered on the same subjects you discuss and would love to have you share some stories/information. I know my
    viewers would appreciate your work. If you’re even remotely interested, feel free to send me an email.

  6. I absolutely love your website.. Pleasant colors & theme.
    Did you build this site yourself? Please reply back as I’m planning to create my
    own personal site and want to learn where you got
    this from or what the theme is named. Thanks!

  7. certainly like your website however you have to check the spelling
    on quite a few of your posts. A number of them are rife with spelling issues and I to find it very bothersome to inform the
    truth on the other hand I will certainly come again again.

  8. My brother suggested I might like this website. He was entirely right.

    This post truly made my day. You cann’t imagine just
    how much time I had spent for this info! Thanks!

  9. Appreciating the commitment you put into your site and in depth information you provide.
    It’s good to come across a blog every once in a while that isn’t the same outdated rehashed information. Great read!

    I’ve saved your site and I’m including your RSS feeds to my Google account.

  10. Having read this I thought it was rather informative.
    I appreciate you spending some time and energy to put this information together.
    I once again find myself personally spending a significant amount of time both reading and leaving comments.
    But so what, it was still worthwhile!

  11. I was curious if you ever considered changing the layout of
    your blog? Its very well written; I love what youve got to say.
    But maybe you could a little more in the way of
    content so people could connect with it better. Youve got
    an awful lot of text for only having 1 or two pictures.
    Maybe you could space it out better?

  12. Hi, I do think this is a great site. I stumbledupon it ;) I’m
    going to revisit yet again since i have bookmarked it.
    Money and freedom is the best way to change, may you be
    rich and continue to guide other people.

  13. We’re a group of volunteers and opening a new scheme in our community.
    Your site offered us with valuable information to work
    on. You’ve done a formidable job and our whole community will be grateful to you.

  14. Fantastic post however I was wanting to know if you
    could write a litte more on this subject? I’d be very grateful if you could elaborate a little bit further.

    Many thanks!

  15. Normally I do not learn post on blogs, but I would like to say that this write-up very forced me to take a look at and do it!

    Your writing style has been amazed me. Thank you, very great
    post.

  16. A person essentially lend a hand to make critically articles I would state.
    That is the first time I frequented your web page and to this point?
    I surprised with the research you made to make this particular
    put up extraordinary. Wonderful job!

  17. Hi, i think that i saw you visited my site thus i came to “return the favor”.I am trying to find things to improve my web site!I suppose its ok to use a few of your ideas!!

  18. Thanks , I’ve just been searching for information about this subject for a while and yours
    is the greatest I have came upon till now. However, what about the
    bottom line? Are you sure concerning the source?

  19. Good day! Would you mind if I share your blog with my myspace
    group? There’s a lot of people that I think would really enjoy
    your content. Please let me know. Thank you

  20. I think this is one of the most significant
    info for me. And i’m glad reading your article.
    But wanna remark on few general things, The web site
    style is perfect, the articles is really nice : D. Good job, cheers

  21. Everything published was actually very logical.
    However, think about this, suppose you added a little information?
    I am not suggesting your content is not solid,
    however suppose you added a headline to maybe get people’s
    attention? I mean Day 16: Measure Performance Before Optimizing | Carlos Oliveira – Optimization & Engineering is kinda plain. You could glance at Yahoo’s home page and
    see how they create post titles to grab people to click.
    You might try adding a video or a picture or two to grab people excited about what you’ve got to say.
    Just my opinion, it might bring your website a little livelier.

  22. hi!,I love your writing so much! share we communicate
    more about your article on AOL? I require a specialist in this space to
    solve my problem. May be that is you! Having a look ahead
    to see you.

  23. Wow that was unusual. I just wrote an incredibly long comment but after I clicked submit my comment didn’t show up.
    Grrrr… well I’m not writing all that over again. Anyhow, just wanted to say fantastic
    blog!

  24. Howdy! I understand this is sort of off-topic but I had to ask.
    Does running a well-established website like yours require a large amount of work?

    I am completely new to operating a blog however I do write in my journal everyday.
    I’d like to start a blog so I will be able to share my experience and
    thoughts online. Please let me know if you have any kind of recommendations or tips for brand new aspiring
    bloggers. Appreciate it!

  25. Hey would you mind letting me know which webhost you’re working with?
    I’ve loaded your blog in 3 different browsers and I must say this blog loads a lot quicker then most.
    Can you recommend a good internet hosting provider at a honest price?
    Cheers, I appreciate it!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.